On 4/7/09, breno <[email protected]> wrote:
> On Mon, Apr 6, 2009 at 5:13 PM, Gabor Szabo <[email protected]> wrote:
>  > On 4/6/09, j <[email protected]> wrote:
>  >> Can anyone send an example of embedding an image in code as a scalar and
>  >> using with Wx::Bitmap?  Thanks.
>  >>
>  > Try to look at Wx::Demo on CPAN. Maybe it has one.
>  >
>
>
> This is what I did for embedding an icon to Padre::Plugin::Catalyst:
>
>   - created a XPM file (just edited a png then saved as xpm using gimp);
>   - opened the file in a text editor, and ripped off the C string array
>  (ok, ok, static char * xpm[]) as a Perl array reference;
>   - used the Wx::Bitmap->newFromXPM() constructor, passing the array ref.
>
>  It worked like a charm. The only thing you need to worry with this is
>  escaping any string-termination character from each string inside the
>  array (or just use q{} to wrap each element if you don't want the
>  trouble).
>
>  Since you specifically asked for an example, here's my code. I did
>  this in a hurry, so there are probably a lot better ways to do it.
>  Feel free to share them :-)
>
>  -------------------------8<---------------------------
>  my $icon = [
>
>  '16 16 46 1'   , '   c None'   , '.  c #D15C5C', '+  c #E88888', '@  c 
> #E10000',
>  '#  c #D03131' , '$  c #D26262', '%  c #D26161', '&  c #E99F9F', '*  c 
> #EFACAC',
>  '=  c #EFADAD' , '-  c #E79090', ';  c #D14949', '>  c #D22727', ',  c 
> #E26666',
>  '\'  c #E26363', ')  c #E26464', '!  c #D42A2A', '~  c #D40101', '{  c 
> #D50B0B',
>  ']  c #D71313' , '^  c #D50C0C', '/  c #D40404', '(  c #D26767', '_  c 
> #DF5353',
>  ':  c #E15B5B' , '<  c #D95D5D', '[  c #D21313', '}  c #D30000', '|  c 
> #DA0000',
>  '1  c #D90000' , '2  c #D31111', '3  c #D14646', '4  c #DC1313', '5  c 
> #EC0000',
>  '6  c #E20000' , '7  c #F00000', '8  c #F20000', '9  c #D33232', '0  c 
> #D64646',
>  'a  c #D46969' , 'b  c #D35555', 'c  c #D23A3A', 'd  c #E89090', 'e  c 
> #E98E8E',
>  'f  c #D60000' , 'g  c #D70101', '                ', '            .   ',
>  '            +   ', '            @#  ', '                '  , '
>         ',
>  '        $%      ', '       &*=-;    ', '      >,\'\')!    ', '
>  ~{]]^/    ',
>  '(_: < [}|1}2    ', '345    67869    ', ' 0a         b c ', '
>     de'  ,
>  '              fg', '                ',
>  ];
>
>  return Wx::Bitmap->newFromXPM( $icon );
>
>  ------------------------->8---------------------------
>
>
>  If you need more information, check out:
>
>  http://docs.wxwidgets.org/2.8.8/wx_wxbitmap.html#wxbitmap
>

and just to put it in context here is the full source code:

http://svn.perlide.org/padre/trunk/Padre-Plugin-Catalyst/lib/Padre/Plugin/Catalyst.pm

Gabor

Reply via email to