简体   繁体   English

如何使用有两种颜色的 python PIL 创建图像?

[英]How Can I create an image with python PIL where there are two colors?

Here is an example of the output I want to generate.这是我要生成的输出示例。 I'm able to create an image with one color, but I don't have idea of how can use two colors, and how to color only certain parts of the image我可以用一种颜色创建图像,但我不知道如何使用两种颜色,以及如何只为图像的某些部分着色图片尺寸. .

I solved in this way.我是这样解决的。 I created two image with two different colors, and then paste them in another one image.我用两种不同的颜色创建了两个图像,然后将它们粘贴到另一个图像中。

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

I got my result.我得到了我的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM