From 3b15bd93198048390e6fbbc70cef7a29f4f10cd5 Mon Sep 17 00:00:00 2001 From: Zach Pearson Date: Sat, 16 Jul 2022 10:55:37 -0700 Subject: [PATCH] compat.py: Add utility function to get raw bytes from QImages --- qtpy/compat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/qtpy/compat.py b/qtpy/compat.py index 4c6d428f..65367fe4 100644 --- a/qtpy/compat.py +++ b/qtpy/compat.py @@ -12,6 +12,7 @@ PYQT6, PYSIDE2, PYSIDE6, + QtBindingsNotFoundError, ) from .QtWidgets import QFileDialog @@ -200,3 +201,14 @@ def isalive(obj): return shiboken.isValid(obj) return None + + +# ============================================================================= +def getimagebytes(qimage): + if PYQT5: + return qimage.bits().asstring(qimage.byteCount()) + if PYQT6: + return qimage.bits().asstring(qimage.sizeInBytes()) + if PYSIDE2 or PYSIDE6: + return qimage.bits().tobytes() + raise QtBindingsNotFoundError()