加载图像像素数据会产生意外结果-Python-枕头

时间:2019-06-14 19:40:33

标签: python image python-imaging-library

为什么第二次调用image.getdata()返回不同的结果?

from PIL import Image

def write():
    image    = Image.open('image.jpg')
    newimage = Image.new(image.mode, image.size)

    pixels   = [p for p in image.getdata()]

    for i in range(100):
        pixels[i] = (255,255,255)
    newimage.putdata(pixels)
    newimage.save('newimage.jpg')

    print(list(newimage.getdata())[0:10])
def read():
    image  = Image.open('newimage.jpg')
    pixels = [p for p in image.getdata()]

    print(list(image.getdata())[0:10])
write()
read()

它给我以下结果: enter image description here

为什么第二组数据与第一组数据不同?

0 个答案:

没有答案