Python 为什么PIL.ImageColor.getcolor()只返回白色或黑色?
我有以下代码:Python 为什么PIL.ImageColor.getcolor()只返回白色或黑色?,python,python-imaging-library,Python,Python Imaging Library,我有以下代码: from PIL import Image, ImageColor i = Image.new('1', (1, 1)) i.putpixel((0, 0), ImageColor.getcolor('black','1')) i.save('simplePixel.png') 摘自此 运行此操作将生成一个1像素的黑色图像。如果我将颜色更改为红色,例如: ImageColor.getcolor('red','1') 我得到一个白色像素而不是红色。我试过黄色、绿色和蓝色;它们都
from PIL import Image, ImageColor
i = Image.new('1', (1, 1))
i.putpixel((0, 0), ImageColor.getcolor('black','1'))
i.save('simplePixel.png')
摘自此
运行此操作将生成一个1像素的黑色图像。如果我将颜色更改为红色,例如:
ImageColor.getcolor('red','1')
我得到一个白色像素而不是红色。我试过黄色、绿色和蓝色;它们都会产生一个白色像素。如何修复此问题?我的模式错误:
from PIL import Image, ImageColor
i = Image.new('RGB', (1, 1))
i.putpixel((0, 0), ImageColor.getcolor('red','RGB'))
i.save('simplePixel.png')
我将'1'
替换为'RGB'
,现在它可以工作了