ImageFromStream - which stream works?

Thanks for taking the time to respond.
Yes, that's exactly what I tried. And I get the error that it's
expecting a stream or a file-type object. Why would that be?

A StringIO/cStringIO object or something else which implements the
necessary methods...

>> If I try
>>
>> pic = wx.Image(StringIO.StringIO.getvalue())
>>
>> I don't get an error for passing the wrong type, but it fails in my case
>> with " 'charmap' codec can't decode byte 0x90 in position 191: character
>> maps to <undefined>".
>
> According to the wxPython section of the wxWindows documentation on
> wx.Image:
> wxImage(name, flag) Loads an image from a file
>
> It thinks that the image data is a file name...that's obviously not
> going to work.
>

I realize that, theoretically, it is not the right type. But whereas
Python actually complains about the wrong type when I use
ImageFromStream, it does not complain when I just use wx.Image.
(Unfortunately, it complains about decoding, but that's a different
matter.) I don't understand why that would be

Python generally uses a paradigm known as "duck typing". "If it quacks
like a duck..." In Python, there is no type difference between a
filename stored in a string, or an image stored in a string, they are
both strings! You aren't getting a type error when you try passing it
to wx.Image, because you are passing a string, not an integer, tuple,
etc.

Reading the documentation is a good step towards understanding what is
going on.

-- and if StringIO is not
right for ImageFromStream, I don't know what else to use.

By definition:
    "This module implements a file-like class, StringIO, that reads and
     writes a string buffer (also known as memory files)."

To me, it seems as though either you are doing it wrong, or your
platform has some issues.

import StringIO
import wx
wx.__version__

'2.6.1.0'

a = open('gm.jpg', 'rb').read()
b = StringIO.StringIO(a)
c = wx.ImageFromStream(b)
c

<wx._core.Image; proxy of C++ wxImage instance at _a8407a01_p_wxImage>

c.GetWidth(), c.GetHeight()

(573, 781)

- Josiah

ยทยทยท

Derek Croxton <croxton3@yahoo.com> wrote: