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)
This commit is contained in:
KIU Shueng Chuan 2021-05-07 18:09:02 +08:00
parent bfc63bb730
commit 0503f96121

View File

@ -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()