[PyKDE] QImage.bits() should return a string?
phil at riverbankcomputing.co.uk
Wed Nov 12 14:10:01 GMT 2003
On Tuesday 11 November 2003 3:13 pm, Lopez-Gulliver, Roberto wrote:
> Hi all,
> From the PyQt docs on QImage :
> uchar *bits();
> The return value is a sip.voidptr object which is only useful if passed to
> another Python module.
> I'm using the following (swig-ed) to get the bits of the QImage as a
> python raw string so I can manipulate it later using PIL or using it as a
> texture in PyOpenGL. Where data_ptr, n = qimage.bits(), qimage.numBytes()
> PyObject *pointer_to_pystring(long data_ptr, int n)
> return PyString_FromStringAndSize(data_ptr, n);
> This works for me(TM) but I wonder if this should be added/included in
> PyQt by default. Probably under a different name to avoid surprises,
> something like "bits_pystr()" or so.
> Of course, you may say, if we do this for bits() we should do it for all
> the other funcs returning sip.voidptr ...
> Any commments/flames on this?
I think a better solution is to add a method to the sip.voidptr type to do the
conversion so you would do something like...
s = qimage.bits().as_string(qimage.numBytes())
More information about the PyQt