wxImage SaveFile to Stream question

Hello all. I have a staticbitmap, and I want to save the image from it to a
mysql database. Here's how I'm trying to do it. self.liveVideo is the
static bitmap. I do a GetBitmap() and place the reference to the image into
x. Then I try to do a x.SaveFile(). When I give it a filename, then all
works fine. But I don't want to place it on the filesystem, I want to take
it and place it into a MySQLdb Insert statement to place it into a table.
The 4th line, where I list to save it into out2db doesn't work. Can anyone
give me any pointers?

out2db = cStringIO.StringIO()
x = self.liveVideo.GetBitmap()
x.SaveFile('c:\\test.jpg',wx.BITMAP_TYPE_JPEG )
x.SaveFile(out2db, wx.BITMAP_TYPE_JPEG )

I really appreciate it. Thanks for any help!!

-Dave

What I have as a routine to read a JPG and set it in the StaticBitmap is:

What I have now to read the JPG photo from the network camera is:

The code I have to read the JPG from the network camera and set into the
StaticBitmap is:

            WebImage = urllib2.urlopen("%s/jpg/fullsize.jpg"
%self.netCamAddress)
            self.rawJpg = WebImage.read()
            photoStream = cStringIO.StringIO(self.rawJpg)
            photoJpg = wx.ImageFromStream( photoStream )
            photoBmp = wx.BitmapFromImage( photoJpg )
            self.liveVideo.SetBitmap(photoBmp)

and what I have to place that in my database is:

        self.cur.execute("insert into photos(check_transactionKEY, photo)
values(%s, %s)", (checkDetailKey, self.rawJpg ) )
        self.con.commit()

And this works OK because I'm using self.rawJpg from above to insert into
the database, so I get nothing out of the StaticBitmap. And this works,
too. However, I'd love to know if it's possible to 'extract' in some manner
from the StaticBitmap object the equivilent of the data I .read() from the
urllib2.urlopen() call. In otherwords, can I backtrace from the
staticbitmap object the photo that was placed into the wx.ImageFromStream()
and from that extract the data that was placed into cStringIO.StringIO()
such that it's the same as the self.rawJpg above that I got from the
WebImage.read() ??

Thanks for bearing with me on this!

-Dave

a wx.Bitmap is an uncompressed raster image
the image you read from the stream is a jpeg compressed image

If you want to (re)compress into jpeg, or compress into jpeg from scratch when
you start with a bitmap, use it's ConvertToImage() method in oder to convert
it into a wx.Image

wx.Image has the method "SaveFile()" which should accept an IOStream (such as
StringIO) as parameter

myimage = mybitmap.ConvertToImage()
myimage.SaveFile(myStringIO, wx.BITMAP_TYPE_JPEG)

Is that what you were looking for?

Horst

···

On Sunday 30 April 2006 01:37, S. D. Rose wrote:

urllib2.urlopen() call. In otherwords, can I backtrace from the
staticbitmap object the photo that was placed into the wx.ImageFromStream()
and from that extract the data that was placed into cStringIO.StringIO()
such that it's the same as the self.rawJpg above that I got from the
WebImage.read() ??

Horst Herb wrote:

···

On Sunday 30 April 2006 01:37, S. D. Rose wrote:

urllib2.urlopen() call. In otherwords, can I backtrace from the
staticbitmap object the photo that was placed into the wx.ImageFromStream()
and from that extract the data that was placed into cStringIO.StringIO()
such that it's the same as the self.rawJpg above that I got from the
WebImage.read() ??

a wx.Bitmap is an uncompressed raster image
the image you read from the stream is a jpeg compressed image

If you want to (re)compress into jpeg, or compress into jpeg from scratch when you start with a bitmap, use it's ConvertToImage() method in oder to convert it into a wx.Image

wx.Image has the method "SaveFile()" which should accept an IOStream (such as StringIO) as parameter

myimage = mybitmap.ConvertToImage()
myimage.SaveFile(myStringIO, wx.BITMAP_TYPE_JPEG)

Is that what you were looking for?

It's not in wxPython yet though because wxOutputStream needs some work to be able to wrap and redirect to a Python file-like object.

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