How does Python Pillow get all the pixels of an image?

for example, at present, all pixel values of the image can only be obtained by traversing the loop:

image = Image.open("test.png")
width = image.width
height = image.height
image_list = []
for x in range(height):
    scanline_list = []
    for y in range(width):
        pixel = image.getpixel((y, x))
        scanline_list.append(pixel)
    image_list.append(scanline_list)
print(image_list)

is there an easier way to get all the pixels of an image? Similar to returning a list of all pixels of an image directly with the getpixels () method


image itself represents a two-dimensional array of pixels, so it is not necessary to save a two-dimensional array as an one-dimensional array. I think the subject might as well tell us what it takes to get an one-dimensional array of picture pixels.
in addition, pillow has a method to directly obtain a two-dimensional array of pixels:

  refer to the pillow documentation . 
I hope I can help you.

Menu