From 0503f961215196f41bafcb1ba84a43f88543ba86 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Fri, 7 May 2021 18:09:02 +0800 Subject: [PATCH] Format_RGB32 will always have alpha equal 255 this also fixes the assumption that we are on little-endian. In [18]: qimg = QtGui.QImage(1, 1, QtGui.QImage.Format.Format_RGB32) In [19]: qimg.fill(QtCore.Qt.GlobalColor.transparent) In [20]: np.frombuffer(qimg.bits(), dtype=np.uint8) Out[20]: array([ 0, 0, 0, 255], dtype=uint8) --- pyqtgraph/functions.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index 21f00bec..72321201 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1503,7 +1503,6 @@ def imageToArray(img, copy=False, transpose=True): the QImage is collected before the array, there may be trouble). The array will have shape (width, height, (b,g,r,a)). """ - fmt = img.format() img_ptr = img.bits() if QT_LIB.startswith('PyQt'): @@ -1522,8 +1521,6 @@ def imageToArray(img, copy=False, transpose=True): arr = np.frombuffer(img_ptr, dtype=np.ubyte) arr = arr.reshape(img.height(), img.width(), 4) - if fmt == img.Format_RGB32: - arr[...,3] = 255 if copy: arr = arr.copy()