ris*_*glf 3 pointers pixel pyqt4 qimage python-sip
我需要使用PyQt4访问qimage对象中的像素数据.
.pixel()太慢,所以文档说使用scanline()方法.
在c ++中,我可以获取scanline()方法返回的指针,并从缓冲区读取/写入像素RGB值.
使用Python,我得到指向像素缓冲区的SIP voidptr对象,因此我只能使用bytearray读取像素RGB值,但我无法更改原始指针中的值.
有什么建议?
这里有些例子:
from PyQt4 import QtGui, QtCore
img = QtGui.QImage(100, 100, QtGui.QImage.Format_ARGB32)
img.fill(0xdeadbeef)
ptr = img.bits()
ptr.setsize(img.byteCount())
## copy the data out as a string
strData = ptr.asstring()
## get a read-only buffer to access the data
buf = buffer(ptr, 0, img.byteCount())
## view the data as a read-only numpy array
import numpy as np
arr = np.frombuffer(buf, dtype=np.ubyte).reshape(img.height(), img.width(), 4)
## view the data as a writable numpy array
arr = np.asarray(ptr).reshape(img.height(), img.width(), 4)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3236 次 |
| 最近记录: |