Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么PIL.ImageColor.getcolor()只返回白色或黑色?_Python_Python Imaging Library - Fatal编程技术网

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'
,现在它可以工作了