Fix for new QImage API in PyQt 4.9.6

This commit is contained in:
Luke Campagnola 2013-02-11 16:38:13 -05:00
parent 6e0e83e926
commit c80bfb334c

View File

@ -951,8 +951,15 @@ def makeQImage(imgData, alpha=None, copy=True, transpose=True):
ch = ctypes.c_char.from_buffer(imgData, 0) ch = ctypes.c_char.from_buffer(imgData, 0)
img = QtGui.QImage(ch, imgData.shape[1], imgData.shape[0], imgFormat) img = QtGui.QImage(ch, imgData.shape[1], imgData.shape[0], imgFormat)
else: else:
addr = ctypes.addressof(ctypes.c_char.from_buffer(imgData, 0)) #addr = ctypes.addressof(ctypes.c_char.from_buffer(imgData, 0))
img = QtGui.QImage(addr, imgData.shape[1], imgData.shape[0], imgFormat) ## PyQt API for QImage changed between 4.9.3 and 4.9.6 (I don't know exactly which version it was)
## So we first attempt the 4.9.6 API, then fall back to 4.9.3
addr = ctypes.c_char.from_buffer(imgData, 0)
try:
img = QtGui.QImage(addr, imgData.shape[1], imgData.shape[0], imgFormat)
except TypeError:
addr = ctypes.addressof(addr)
img = QtGui.QImage(addr, imgData.shape[1], imgData.shape[0], imgFormat)
img.data = imgData img.data = imgData
return img return img
#try: #try: