from PIL import Image
########获取图片指定像素点的像素
def getPngPix(pngPath = "aa.png",pixelX = 1,pixelY = 1):
img_src = Image.open(pngPath)
img_src = img_src.convert('RGBA')
str_strlist = img_src.load()
data = str_strlist[pixelX,pixelY]
img_src.close()
return data
print(getPngPix())
########获取图片指定像素点的像素
def getPngPix(pngPath = "aa.png",pixelX = 1,pixelY = 1):
img_src = Image.open(pngPath)
img_src = img_src.convert('RGBA')
str_strlist = img_src.load()
data = str_strlist[pixelX,pixelY]
img_src.close()
return data
print(getPngPix())
本文介绍了一种使用Python的PIL库获取PNG图片指定位置像素值的方法。通过打开图片并将其转换为RGBA模式,可以轻松地读取任意位置的像素颜色。
269

被折叠的 条评论
为什么被折叠?



