访问量: 10 次浏览
PIL是Python成像库,它为Python解释器提供了图像编辑功能。PixelAccess类提供了对PIL.Image数据在像素级的读写权限。
访问单个像素是相当慢的。如果你要在一个图像中的所有像素上进行循环,那么使用 Pillow API的其他部分可能会有更快的方法。
putpixel() 修改x,y处的像素。对于单波段图像,颜色是以单一数值给出的,对于多波段图像,是一个元组。
putpixel(self, xy, color)
xy
像素坐标,以(x, y)的形式给出。
value
– 像素值。
一个带有像素的图像。
方法")
# Importing Image from PIL package
from PIL import Image
# creating a image object
image = Image.open(r'C:\Users\System-Pc\Desktop\python.png')
width, height = image.size
for x in range(height):
image.putpixel( (x, x), (0, 0, 0, 255) )
image.show()
方法")
这里我们改变颜色参数。
方法")
# Importing Image from PIL package
from PIL import Image
# creating a image object
image = Image.open(r'C:\Users\System-Pc\Desktop\ybear.jpg')
width, height = image.size
for x in range(height):
image.putpixel( (x, x), (10, 10, 10, 255) )
image.show()
方法")