我想知道在Python中用x和y值绘制像素的最简单方法是什么?
也许最简单的方法是使用PIL (Python Imaging Library),只需4行代码即可实现:
from PIL import Image, ImageColor
im = Image.new('1', (1,1)) # create the Image of size 1 pixel
im.putpixel((0,0), ImageColor.getcolor('black', '1')) # or whatever color you wish
im.save('simplePixel.png') # or any image format
这份文档展示了许多其他自定义的方法,请访问http://pillow.readthedocs.io/en/3.4.x/reference/Image.html#examples。
'RGBA'
是不必要的,一个新的Image.new(mode, size) ⇒ image的参数定义为:'图像的模式定义了图像中像素的类型和深度:RGBA(4x8位像素,真彩色带透明掩码)'
我只是随意从这个列表concepts.htm#mode中取出它,更简单的方法是使用'1 (1位像素,黑白,每字节存储一个像素)'
,我在答案中更新了这个。 - chickity china chinese chicken
print('.')
- whackamadoodle3000