我试图用Integer格式来指定图像的颜色,而不是(R,G,B)格式。我假设我必须在模式"I“中创建一个图像,因为根据文档
图像模式定义图像中像素的类型和深度。当前版本支持以下标准模式:
然而,这似乎是一个灰度图像。这是意料之中吗?有没有一种基于32位整数来指定彩色图像的方法?在我的MWE中,我甚至让PIL决定如何将"red“转换为"I”格式。
米维
from PIL import Image
ImgRGB=Image.new('RGB', (200,200),"red") # create a new blank image
ImgI=Image.new('I', (200,200),"red") # create a new blank image
ImgRGB.show()
ImgI.show()
发布于 2015-08-25 09:53:42
有没有一种基于32位整数来指定彩色图像的方法?
是的,对此使用RGB格式,但使用整数而不是"red“作为颜色参数:
from PIL import Image
r, g, b = 255, 240, 227
intcolor = (b << 16 ) | (g << 8 ) | r
print intcolor # 14938367
ImgRGB = Image.new("RGB", (200, 200), intcolor)
ImgRGB.show()
https://stackoverflow.com/questions/32192671
复制相似问题