Skip to content

Commit

Permalink
Fix image memory issues (maintenance branch) (#1111)
Browse files Browse the repository at this point in the history
* Fix QPixmap references to QImage

This hopefully fixes #1108.

* Add comments to explain why we are stashing references.
  • Loading branch information
corranwebster authored Feb 24, 2022
1 parent c33a76f commit dd05bd0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyface/ui/qt4/util/image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def image_to_bitmap(image):
bitmap : QPixmap
The corresponding QPixmap.
"""
return QPixmap.fromImage(image)
bitmap = QPixmap.fromImage(image)
# keep a reference to the QImage to ensure underlying data is available
bitmap._image = image
return bitmap


def bitmap_to_image(bitmap):
Expand Down Expand Up @@ -166,6 +169,7 @@ def array_to_image(array):
elif channels == 4:
image = QImage(data.data, width, height, bytes_per_line,
QImage.Format.Format_ARGB32)
# keep a reference to the array to ensure underlying data is available
image._numpy_data = data
return image

Expand Down

0 comments on commit dd05bd0

Please sign in to comment.