From: Bradley K. E. <bk...@bk...> - 2006-09-18 04:59:31
|
Hello All, I have a scalar containing a bmp (generated by ChartDirector (http://www.advsofteng.com/cdperl.html)) that I would like to create a Wx::Bitmap from, which I will then draw on a panel. Wx::Bitmap does not seem to be able to do this directly, but I thought I could create a Wx::Bitmap from a Wx::Image. So code looks like: # create a scalar containing the bmp data my $chart_bmp = $chart_object->makeChart2($perlchartdir::BMP); my $bmp = Wx::Bitmap->new( Wx::Image->new( ... ) ); The ... is where I am having problems. I've tried the following forms of the Wx::Image constructor: Wx::Image->new( width, height, data ): my $bmp = Wx::Bitmap->new( Wx::Image->new( 200, 200, $chart_bmp ) ); Gives me an error message of 'not enough data in image constructor at ...'. Wx::Image->new( stream, type, index ): First naive attempt: $bmp = Wx::Bitmap->new( Wx::Image->new( $chart_bmp, wxBITMAP_TYPE_BMP, -1 ) ); Gives me an error message indicating the file does not exist so I assume the constructor thinks that $chart_bmp is a file name. Next attempt: $bmp = Wx::Bitmap->new( Wx::Image->new( \$chart_bmp, wxBITMAP_TYPE_BMP, -1 ) ); Which gives an error message that it is not a GLOB reference. So stream == filehandle. But the point of this is that I don't want to write $chart_bmp to a file, so I tried opening $chart_bmp as an "in memory" file: open my $fh, '<', \$chart_bmp or die "cannot open: $!"; $bmp = Wx::Bitmap->new( Wx::Image->new( $fh, wxBITMAP_TYPE_BMP, -1 ) ); Which gives me an error of 'DIB Header: Image width > 32767 pixels for file.'. I've tested the contents of $chart_bmp by opening a filehandle and printing the contents to the file and it is a valid bitmap. So I am a bit lost as far as where to go next. Is it possible to create a stream from a scalar? I've looked at wxInputStream but the docs indicate that it is not implemented in wxPerl. Am I am being a complete moron and missing something obvious here? Any help/pointers would be greatly appreciated. Thanks, Brad |