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


In reply to Re: What's wrong with this Wx::Bitmap construction? by stefbv
in thread What's wrong with this Wx::Bitmap construction? by isync

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.