PIL选择坐标来制作图像

时间:2013-02-12 11:15:50

标签: python image python-imaging-library

我想从我选择的坐标中创建一个图像。所以我希望每个坐标都设置一个特定的大小,颜色说黑色和2X2,然后将它放在它代表的特定像素上。 我将如何解决这个问题? 函数putpixel是否适用于我想做的事情?

提前致谢

1 个答案:

答案 0 :(得分:3)

使用putpixel执行此操作会很不方便,但并非不可能。由于您说要制作多个像素的点,因此最好使用ImageDraw.rectangle()ellipse()

例如:

import Image
import ImageDraw

img = Image.new("RGB", (400,400), "white")
draw = ImageDraw.Draw(img)

coords = [(100,70), (220, 310), (200,200)]
dotSize = 2

for (x,y) in coords:
    draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="black")

img.show()
相关问题