On Thu, 23 May 2013 16:21:26 -0400, Luke Campagnola <lcamp...@email.unc.edu> wrote: > Howdy, > I am using PyQt 4.10.1 (Py2.7-qt4.8.4-x32) on windows XP. It appears that > on this system, QImage(sip.voidptr, int, int, format) increases the > reference count to the image data object, but does not decrease the > refcount after the QImage is collected. Here's an example session, where I > am generating a QImage from a numpy array: > >>>> from PyQt4 import QtGui >>>> import ctypes, weakref, sys >>>> import numpy as np >>>> data = np.zeros((100,100,4), dtype=np.ubyte) >>>> addr = ctypes.c_char.from_buffer(data,0) >>>> sys.getrefcount(addr) > 2 >>>> img = QtGui.QImage(addr, 100, 100, QtGui.QImage.Format_ARGB32) >>>> sys.getrefcount(addr) # QImage added 1 to reference count > 3 >>>> import weakref >>>> ref = weakref.ref(img) >>>> del img >>>> ref > <weakref at 0161F090; dead> # QImage was collected >>>> sys.getrefcount(addr) # but refcount is still 3 > 3 > > > Can anyone recommend a good way to convert from ndarray to QImage > (preferrably without incurring any memory copy) ?
Using either a sip.voidptr or a string seems to work fine for me with current snapshots. Phil _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt