Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a WxPerl utility that stores and retrieves gif and jpg images from a Database but am having difficulty displaying the decoded image after retrieving it from the database. Here is my sample code to decode and display the base64 encoded string:
use MIME::Base64; # $encoded_image is retrieved from the DB my $decoded = decode_base64($encoded_image); my $image = Wx::Bitmap->new( Wx::Image->new( $decoded, wxBITMAP_TYPE_A +NY) );
I get the error: Can't load image from file...do I need to append an image extension somehow?

Thanks

Replies are listed 'Best First'.
Re: Wxperl displaying decoded image?
by ikegami (Patriarch) on Jun 23, 2009 at 16:15 UTC

    I didn't find documentation on that module, but I've seen documentation for the C++ version. It accepted a file name, a file handle or a string containing an image in XPM format. What you are passing is none of those.

    If the module accepts a Perl file handle (as opposed to a system file handle), the following will do the trick:

    open(my $image_fh, '<', \$decoded); my $image = Wx::Bitmap->new( Wx::Image->new( $image_fh, wxBITMAP_TYPE_ANY ) );

    Requires Perl 5.8.0 or higher.