in reply to What's wrong with this Wx::Bitmap construction?

What's wrong? Nothing. :)

Here is a working example (at least on my system), of an embedded icon. The icon data is from the tkIcons file, part of the Tk::ToolBar module.

package IconFrame; use strict; use warnings; use Carp; use Wx qw[:everything]; use base qw(Wx::Frame); use MIME::Base64; use IO::Scalar; sub new { my $self = shift; $self = $self->SUPER::new( undef, -1, 'Icon list', [ -1, -1 ], [ -1, -1 ], wxDEFAULT_FRAME_STYLE, ); Wx::InitAllImageHandlers(); #- Grid Sizer $self->{sizer} = Wx::GridSizer->new( 1, 1 ); my $d = <main::DATA>; my $img_data = decode_base64($d); my $data = IO::Scalar->new( \$img_data ); my $bmp = $self->make_bitmap_icon($data); #-- Create bitmap buttons my $button = Wx::BitmapButton->new( $self, -1, $bmp, [ -1, -1 ], ) +; #-- Add buttons to grid sizer $self->{sizer}->Add( $button, 0, wxALIGN_CENTRE | wxGROW | wxALL, +2, ); $self->SetSizer( $self->{sizer} ); $self->{sizer}->Fit($self); return $self; } sub make_bitmap_icon { my ($self, $iconfile) = @_; return Wx::Bitmap->new( Wx::Image->new( $iconfile, wxBITMAP_TYPE_ANY, -1, ), ); } 1; package IconApp; use base 'Wx::App'; sub OnInit { my $frame = IconFrame->new(); $frame->Show( 1 ); } package main; use strict; use warnings; my $app = IconApp->new(); $app->MainLoop; __DATA__ R0lGODlhEAAQAIIAAPwCBMT+xATCBASCBARCBAQCBEQCBAAAACH5BAEAAAAALAAAAAAQAB +AAAAM2CLrc/itAF8RkdVyVye4FpzUgJwijORCGUhDDOZbLG6Nd2xjwibIQ2y80sRGIl4I +BuWk6Af4EACH+aENyZWF0ZWQgYnkgQk1QVG9HSUYgUHJvIHZlcnNpb24gMi41DQqpIERl +dmVsQ29yIDE5OTcsMTk5OC4gQWxsIHJpZ2h0cyByZXNlcnZlZC4NCmh0dHA6Ly93d3cuZ +GV2ZWxjb3IuY29tADs=

The folowing script, can be used, to create the data from gif files. Other images types can (must?) be converted first to gif format.

use strict; use warnings; use MIME::Base64; my $img_file = $ARGV[0]; open my $file_fh, '<', $img_file or die "Can't open file ",$img_file, ": $!"; binmode $file_fh; my $photo = do {local $/; <$file_fh>}; # Encode my $stream = encode_base64($photo, q{}) or die $!; print "$stream\n"; close $file_fh;

Regards, Stefan