【发布时间】:2017-05-25 22:43:43
【问题描述】:
我想知道,在 python 中用 x 和 y 值绘制像素的最简单方法是什么?
【问题讨论】:
-
这可能不止一个像素,但它仍然绘制一个像素:
print('.')
标签: python
我想知道,在 python 中用 x 和 y 值绘制像素的最简单方法是什么?
【问题讨论】:
print('.')
标签: python
可能最简单的方法是使用PIL(Python 图像库),它可以在 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的参数,定义为:'mode of an image defines the type and depth of a pixel in the image: RGBA (4x8-bit pixels, true colour with transparency mask)'我只是从这个列表中随意取的@987654325 @,更简单的是使用'1 (1-bit pixels, black and white, stored with one pixel per byte)',我在答案中更新了这个