我试图用整数格式而不是(R,G,B)格式指定图像的颜色。我假设我必须在模式“I”中创建一个图像,因为根据documentation:
The mode of an image defines the type and depth of a pixel in the image. The current release supports the following standard modes:
- 1 (1-bit pixels, black and white, stored with one pixel per byte)
- L (8-bit pixels, black and white)
- P (8-bit pixels, mapped to any other mode using a colour palette)
- RGB (3x8-bit pixels, true colour)
- RGBA (4x8-bit pixels, true colour with transparency mask)
- CMYK (4x8-bit pixels, colour separation)
- YCbCr (3x8-bit pixels, colour video format)
- I (32-bit signed integer pixels)
- F (32-bit floating point pixels)
然而,这似乎是一个灰度图像。这是预期的吗?有没有基于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()
是的,使用RGB格式,但是使用整数而不是“red”作为颜色参数:
相关问题 更多 >
编程相关推荐