Saving a wx.Image as a BLOB in a database

I'm able to display images stored in a database as BLOBs using wx.ImageFromStream(), but if the user modifies the image by loading a new file, what's the best way to convert from a wx.Image back to a stream so that it can be written back to the database?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

Ed Leafe wrote:

    I'm able to display images stored in a database as BLOBs using wx.ImageFromStream(), but if the user modifies the image by loading a new file, what's the best way to convert from a wx.Image back to a stream so that it can be written back to the database?

I haven't yet created the code that will let a wx.OutputStream automatically wrap a python file-like object like we have for wx.InputStream. So until that's done you'll need to either save to a file and read the data back from there, or do something like convert the wx.Image to a PIL Image and get your data stream from it.

···

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

Is there any way of detecting what type of image was in the database? Currently, there can be JPGs, GIFs, PNGs, etc., in the database. ImageFromStream() seems to be able to handle each type OK without me telling it which type of image it is; is there a way to determine which handler was used?

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Jun 24, 2006, at 4:52 PM, Robin Dunn wrote:

    I'm able to display images stored in a database as BLOBs using wx.ImageFromStream(), but if the user modifies the image by loading a new file, what's the best way to convert from a wx.Image back to a stream so that it can be written back to the database?

I haven't yet created the code that will let a wx.OutputStream automatically wrap a python file-like object like we have for wx.InputStream. So until that's done you'll need to either save to a file and read the data back from there, or do something like convert the wx.Image to a PIL Image and get your data stream from it.

Ed Leafe wrote:

    Is there any way of detecting what type of image was in the database? Currently, there can be JPGs, GIFs, PNGs, etc., in the database. ImageFromStream() seems to be able to handle each type OK without me telling it which type of image it is; is there a way to determine which handler was used?

I don't see anything like that. The wxImage class doesn't appear to keep track which handler was used to load the image.

···

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