如何使用 python PIL 创建有两种颜色的图像?
How Can I create an image with python PIL where there are two colors?
这是我要生成的输出示例。我可以用一种颜色创建图像,但我不知道如何使用两种颜色,以及如何只为图像的某些部分着色 。
我是这样解决的。我用两种不同的颜色创建了两张图片,然后将它们粘贴到另一张图片中。
width = 400
height = 300
img = Image.new( mode = "RGB", size = (width, height), color = (209, 123, 193) )
#First IMG
img2 = Image.new( mode = "RGB", size = (width, height + 400), color = (255, 255, 255) )
#Second IMG
img3 = Image.new('RGB', (img.width, img.height + img2.height)) img3.paste(img, (0, 0)) img3.paste(img2, (img.width, 0))
#IMG + IMG2
我得到了我的结果。
这是我要生成的输出示例。我可以用一种颜色创建图像,但我不知道如何使用两种颜色,以及如何只为图像的某些部分着色
我是这样解决的。我用两种不同的颜色创建了两张图片,然后将它们粘贴到另一张图片中。
width = 400
height = 300
img = Image.new( mode = "RGB", size = (width, height), color = (209, 123, 193) )
#First IMG
img2 = Image.new( mode = "RGB", size = (width, height + 400), color = (255, 255, 255) )
#Second IMG
img3 = Image.new('RGB', (img.width, img.height + img2.height)) img3.paste(img, (0, 0)) img3.paste(img2, (img.width, 0))
#IMG + IMG2
我得到了我的结果。