基于这个答案 https://dev59.com/ZXVD5IYBdhLWcg3wJIIK#769221,我编写了以下代码打印抓取区域中的值:
import sys
from PyQt4.QtGui import QPixmap, QApplication
app = QApplication(sys.argv)
# img is QImage type
img = QPixmap.grabWindow(
QApplication.desktop().winId(),
x=00,
y=100,
height=20,
width=20,
).toImage()
for x in range(0,20):
for y in range(0,20):
print( "({},{}) = {}".format( x,y,(img.pixel(x,y)) ) )
但是像素的显示方式如下:
(0,0) = 4285163107
(0,1) = 4285163107
(0,2) = 4285163107
(0,3) = 4285163107
(0,4) = 4285163107
(0,5) = 4285163107
如何获取从QPixmap获取的QImage像素的RGB值?(最好在16、24、32位屏幕色深下工作的解决方案)?
示例输出:
(0,0) = (0,0,0)
...
(10,15) = (127,15,256)
(适用于Linux的解决方案,使用Python3编写)