hendra kusuma wrote:> I''m trying to save a bitmap into Postgresql > using wxruby as front end (you see, wxFilePickerCtrl, and wxStaticBitmap) > and bitmap is displayed on wxStaticBitmap after selecting file with > wxFilePickerCtrl > and saved into db with pressing save button > I''m using Ruby DBI to connect to databaseUse Wx::Image.read and Wx::Image#write plus ruby''s in-built StringIO class to have image data in a recognised format (eg PNG, JPG) in a ruby string variable: img_str = StringIO.new('''') wx_img.write(img_str, Wx::BITMAP_TYPE_PNG) # img_str now contains image data and can be saved to the database, probably in a BLOB column # row has been retrieved from the database, and column [2] contains the image data img_str = StringIO.new(column[2]) wx_img = Wx::Image.read(img_str, Wx::BITMAP_TYPE_PNG) Note that unlike normal file-based constructors for Wx::Image, the type declarations are mandatory for write and read, because the image file format can''t be inferred from the file suffix. I don''t know the exact DBI syntax, and the column type declaration needed for PostgreSQL but I expect you can figure this out. hth a
Alex Fenton
2009-Jul-14 07:42 UTC
[wxruby-users] form to save and load image to/from database
hendra kusuma wrote:> Problem is, I don''t find any widget to display the picture > (the doc says that wxStaticBitmap should only be used for displaying > small image such as icon)For more general drawing of images (and other things) draw the image as a Wx::Bitmap upon a Wx::Window. This is pretty easy, see the samples/drawing/image.rb for the model of this. PS - might you be able to alter your quoting settings when replying to messages, please, so it uses a recognised quoting character like ''>''? Your emails show up with all the original, reply and new text looking identical, so it''s hard to find your reply. alex