Skip to content

Commit 3b15bd9

Browse files
committed
compat.py: Add utility function to get raw bytes from QImages
1 parent 3238de7 commit 3b15bd9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

qtpy/compat.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
PYQT6,
1313
PYSIDE2,
1414
PYSIDE6,
15+
QtBindingsNotFoundError,
1516
)
1617
from .QtWidgets import QFileDialog
1718

@@ -200,3 +201,14 @@ def isalive(obj):
200201

201202
return shiboken.isValid(obj)
202203
return None
204+
205+
206+
# =============================================================================
207+
def getimagebytes(qimage):
208+
if PYQT5:
209+
return qimage.bits().asstring(qimage.byteCount())
210+
if PYQT6:
211+
return qimage.bits().asstring(qimage.sizeInBytes())
212+
if PYSIDE2 or PYSIDE6:
213+
return qimage.bits().tobytes()
214+
raise QtBindingsNotFoundError()

0 commit comments

Comments
 (0)