Hi, all...
I'm loading up an image into a bitmap button (for a link) like so:
$obj->{bitmap_helpPage} = Wx::BitmapButton->new($obj->{pane_Help},
-1, Wx::Bitmap->new("C:\\Program Files\\XFX\\SyrINJ\\XFX3d_logo.jpg",
wxBITMAP_TYPE_ANY));
The whole thing is to be packaged up with PerlApp for Win32 as a
binary executable. This works fine mostly, except:
...there's no guarantee that the user will install the program into
C:\Program Files\XFX\SyrINJ. They might have their programs installed
on D:\ or they might decide to stick it into a sorted folder like
C:\Program Files\Art\3D\ for instance, in which case the image will be
there, instead.
Is there a normal way to deal with this issue? It seems like it must
be a common issue and stuff. Maybe embed the program? Maybe there's an
ENV key that would know what folder to look in?
Just convert the image to XPM and embed it in the Perl program.
XPM is a text based image format (you can read it in a texteditor) that
has it's origins on Linux but works on all platforms within wxPerl.
I convert my images to XPM by using ImageMagicks convert.exe:
:>convert.exe logo.bmp logo.xpm
...but there are probably other programs that can do that for you to.
I have created an Image.pm module which has become quite a library of
images that I use in many of my wxPerl programs.
Here's a sample with two small icons:
***************
** Images.pm **
#!/usr/bin/perl -w
package Images;
use Wx qw[:everything];
use strict;
sub img_excel {
my $img = q~
/* XPM */
static char *excel[] = {
/* columns rows colors chars-per-pixel */
"16 16 4 1",
" c #848484",
". c #008400",
"X c gray100",
"o c black",
/* pixels */
" . . . . . . . .",
". . . . . . . . ",
" .XXXXXXXXXXXX .",
". X. . XXX . X. ",
" .X . . X . .X .",
". X.X. . . . X. ",
" .XX.X. . . XX .",
". XXX.X. . XXX. ",
" .XX. .X. . .X .",
". X. . .X. . X. ",
" .X . . .X. .X .",
". X. . . .X. .. ",
" .XXXXXXX . . .",
". XXXXXXXXXXXX. ",
" . . . . . . . .",
". . . . . . . . "};
~;
my $data = [ map { m/^"(.*)"/ ? ( $1 ) : () } split /\n/, $img ];
my $xpm = Wx::Bitmap->newFromXPM( $data );
return $xpm;
}
sub img_url {
my $img = q~
/* XPM */
static char *url[] = {
/* columns rows colors chars-per-pixel */
"16 16 9 1",
" c black",
". c #808080",
"X c #C0C0C0",
"o c #008000",
"O c gray100",
"+ c blue",
"@ c navy",
"# c gray100",
"$ c None",
/* pixels */
"$$$$$$$$$$$$$$$$",
"$$$ $$$$$$$",
"$$ ..Xooo $$$$$$",
"$ OXOooooo $$$$$",
" .+OX++++oo $$$$",
" [EMAIL PROTECTED] $$$$",
" [EMAIL PROTECTED]@o $$$$",
" ++oooooo++ $$$$",
" ++++oooo.+ $$$$",
" @+++ @ X$",
"$ +@ XOXO OXOX $",
"$$ X X ",
"$$$ O . XXX . O ",
"$$$ X X ",
"$$$$ XOXO OXOX X",
"$$$$X $ $$"};
~;
my $data = [ map { m/^"(.*)"/ ? ( $1 ) : () } split /\n/, $img ];
my $xpm = Wx::Bitmap->newFromXPM( $data );
return $xpm;
}
1;
** Images.pm **
***************
#########################
# Usage as bitmap:
$self->{bitmap_1} = Wx::StaticBitmap->new(
$self, -1, (Images::img_url()), wxDefaultPosition, wxDefaultSize,
);
#########################
# Or as an Icon
my $icon = Wx::Icon->new();
$icon->CopyFromBitmap( Images::img_excel() );
$self->SetIcon($icon);
Some things to consider:
*Try to minimise the ammount of colours in the original image as much as
possible. (without losing quality)
*Large or colourfull images might use '~' (tilde) as a pixel sign which
will break the q~~ quoting. Using HEREDOCS might fix that
wxGlade users:
You can also use this trick from wxGlade but you need to explicitly set
the size(!) and ofcourse there won't be a preview.
Regards,
Huub Peters