导语:
本文主要介绍了关于python如何读取像素值的相关知识,包括opencv python,以及照片分辨率python像素这些编程知识,希望对大家有参考作用。
使用image模块中的getpixel函数获得像素值。
GetPixel函数检索指定坐标点的像素的RGB颜色值。
函数原型:
COLORREF GetPixel(HDC hdc, int nXPos, int nYPos)
参数:
hdc:设备环境句柄。
nXPos:指定要检查的像素点的逻辑X轴坐标。
nYPos:指定要检查的像素点的逻辑Y轴坐标。
示例:
import Image
import sys
im = Image.open(sys.argv[1])
width = im.size[0]
height = im.size[1]
print "/* width:%d */"%(width)
print "/* height:%d */"%(height)
count = 0
for h in range(0, height):
for w in range(0, width):
pixel = im.getpixel((w, h))
for i in range(0,3):
count = (count+1)%16
if (count == 0):
print "0x%02x,/n"%(pixel[i]),
else:
print "0x%02x,"%(pixel[i]),
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ python随机数种子在多维数组中的使用12/25
- ♥ Python可以做桌面应用吗?10/29
- ♥ Python美丽的太阳系——瞎了你的眼睛!12/18
- ♥ len在python中是什么意思10/27
- ♥ python函数的形式参数和实际参数有什么区别?09/11
- ♥ Python流控语句01/10
内容反馈