hmeine / qimage2ndarray

qimage2ndarray is a small python extension for quickly converting between QImages and numpy.ndarrays (in both directions).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QImage format can not be determined

Oli4 opened this issue · comments

I get the following error when using qimage2ndarray with pyside6.3 or pyside6.4 (I haven't tested other versions)

File "/home/morelle/.cache/pypoetry/virtualenvs/eyelab--UaGblaG-py3.10/lib/python3.10/site-packages/qimage2ndarray/qimageview_python.py", line 136, in qimageview
    if qimage_format.bits not in (8, 16, 32, 64):
AttributeError: 'NoneType' object has no attribute 'bits'

I think the problematic line is here:

if name in dir(QtGui.QImage):

The format names do not seem to be available in the QImage dir anymore and QImage.format()also return a format string in the form Format.Format_RGB32 for example. It works if you replace in the line above QtGui.QImage it with QtGui.QImage.Format

Currently I place this code directly after the first qimage2ndarray import to patch the issue until a new release

import qimage2ndarray
# Monkeypatch qimage2ndarray until new version (> 1.9.0)
for name, qimage_format in qimage2ndarray.qimageview_python.FORMATS.items():
    if name in dir(QtGui.QImage.Format):
        qimage_format.code = getattr(QtGui.QImage, name)

Thanks a lot for qimage2ndarray. I use it a lot.

With PySide6, while QImage no longer has Format_RGB32 and friends in its dir(), directly accessing it still works, and QImage.Format_Indexed8 is QImage.Format.Format_Indexed8 is True.

In PyQt5, those constants are just ints and QImage.Format_Indexed8 == QImage.Format.Format_Indexed8 holds, but not QImage.Format_Indexed8 is QImage.Format.Format_Indexed8.