img2py to string

Hi,

To create a texture for openGL and using PIL, I am using following code:

textureSurface = Image.open(iconFile)
textureData = textureSurface.convert( “RGBA”).tostring()

When generating “textureData” from a file generated using img2py script and :

textureData = myfile.GetData()

I am not getting the correct data. How do I solve this?

Prashant

···

Connect with friends all over the world. Get Yahoo! India Messenger.

Prashant Saxena wrote:

Hi,

To create a texture for openGL and using PIL, I am using following code:

textureSurface = Image.open(iconFile)
textureData = textureSurface.convert( "RGBA").tostring()

When generating "textureData" from a file generated using img2py script and :

textureData = myfile.GetData()

I am not getting the correct data.

That's because it is not raw RGBA data, but is the same binary data as a .png image file.

How do I solve this?

You can get the RGB data as a string by converting to a wx.Image first, something like this:

  textureData = myfile.GetImage().GetData()

And you can get the alpha from the wx.Image as a separate string with GetAlphaData().

If you use the GetBitmap function in the img2py file then there is a method for copying the image data in the wx.Bitmap to a writable buffer object (array.array, numpy.array, etc.) in various formats, see wxPython API Documentation — wxPython Phoenix 4.2.2 documentation

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!