Answers for "check color of point png python"

2

python get pixel values from image

from PIL import Image

img = Image.open('example.png')
imgWidth, imgHeight = img.size
img = img.convert("RGBA")
imgdata = img.getdata()

x_pos = 0
y_pos = 1

pixel_value = []
x = []
y = []

for item in imgdata:
    if (x_pos) == imgWidth:
        x_pos = 1
        y_pos += 1
    else:
        x_pos += 1

    if item[3] != 0:
        pixel_value.append(item[2])
        x.append(x_pos)
        y.append(y_pos)

pixel_value, x, y = zip(*sorted(zip(pixel_value, x, y), reverse=True))

print(f'{pixel_value}n{x}n{y}')
Posted by: Guest on October-04-2020
0

how to get RGB value from pixel in screen live python

import PIL.ImageGrab
rgb = PIL.ImageGrab.grab().load()[x,y]
Posted by: Guest on August-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language