in reply to Bitmap for beginners (Perl Tk)

Hi!

use Tk; my $top = new MainWindow; my $pic = $top->Photo(-file=>"up.bmp"); $top->Button(-image=>$pic)->pack(); MainLoop();
Hope this helps.

Regards, mawe

Replies are listed 'Best First'.
Re^2: Bitmap for beginners (Perl Tk)
by TonyDonker (Novice) on Feb 16, 2005 at 08:09 UTC
    Hi mawe, thanks for your help. I receive the following message:

    32-bits BMP file not (yet) supported at ../Image.pm at line 21

    Any ideas?
    Thanks,
    Ton
      Hi!

      As zentara mentions below, you have to base64 encode the image first. Here is a snippet from Matering Perl/Tk which shows one was to do it:

      sub encode_photo_data { my($file) = @_; use MIME::Base64; my ($bin, $data, $stat); open PHOTO, $file or die "Cannot open $file: $!"; while ( $stat = sysread PHOTO, $bin, 57 * 17 ) { $data .= encode_base64($bin); } close PHOTO or die $!; die "sysread error: $!" unless defined $stat; $data; } # end encode_photo_data

      Regards, mawe

        Hi mawe,

        OK - so I tried this:

        use Tk;
        my $top = new MainWindow;
        my $pic = $top->Photo(-file=>encode_photo_data("up.bmp"));
        $top->Button(-image=>$pic)->pack();
        MainLoop();

        sub encode_photo_data {
        my($file) = @_;
        use MIME::Base64;
        my ($bin, $data, $stat);
        open PHOTO, $file or die "Cannot open $file: $!";
        while ( $stat = sysread PHOTO, $bin, 57 * 17 ) {
        $data .= encode_base64($bin);
        }
        close PHOTO or die $!;
        die "sysread error: $!" unless defined $stat;
        $data;
        } # end encode_photo_data

        now it returns 'Cannot open + a lot of binary data...?

        What am I doing wrong?
        I receive the message:
        Cannot open '

        ***lots of binary data***

        ' in mode 'r' at ../Image.pm line 21