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