j wrote:
Can anyone send an example of embedding an image in code as a scalar and using with Wx::Bitmap? Thanks.

Hi,

This is what I sent to the list in reply to someone else (back in 2007):

<snip>
I use something like this:
I convert the image to XPM with ImageMagick (eg.)

 convert image.bmp image.xpm

This is a "textbased" format so you can open it in an editor and then use
it in code like so:

# ---------------------------------------------------------------------
sub img_checked {
my $img = q~
/* XPM */
static char *check[] = {
/* columns rows colors chars-per-pixel */
"16 16 5 1",
"  c black",
". c #848284",
"X c #C6C3C6",
"o c gray100",
"O c white",
/* pixels */
"oooooooooooooooo",
"oooooooooooooooo",
"oo............oo",
"oo.          Xoo",
"oo. OOOOOOOOOXoo",
"oo. OOOOOOO OXoo",
"oo. OOOOOO  OXoo",
"oo. O OOO   OXoo",
"oo. O  O   OOXoo",
"oo. O     OOOXoo",
"oo. OO   OOOOXoo",
"oo. OOO OOOOOXoo",
"oo. OOOOOOOOOXoo",
"oo.XXXXXXXXXXXoo",
"oooooooooooooooo",
"oooooooooooooooo"};
~;
my $data = [ map { m/^"(.*)"/ ? ( $1 ) : () } split /\n/, $img ];
my $xpm = Wx::Bitmap->newFromXPM( $data );
return $xpm;
}

# You can call it like this ....:
my $img_checked = Wx::StaticBitmap->new(
 $self->{panel},
 -1,
 img_checked(),
);

# or in an Imagelist:
my $img_list = Wx::ImageList->new( 16, 16, 1 );
$img_list->Add( img_checked() );

# or an icon:
my $icon = Wx::Icon->new();
$icon->CopyFromBitmap( $img_checked() );
$self->SetIcon($icon);

# ---------------------------------------------------------------------

Still use this trick myself :-)

Cheers,
Huub Peters

Reply via email to