in reply to Re: Bitmap for beginners (Perl Tk)
in thread Bitmap for beginners (Perl Tk)

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

Replies are listed 'Best First'.
Re^3: Bitmap for beginners (Perl Tk)
by mawe (Hermit) on Feb 16, 2005 at 08:37 UTC
    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
        Hi!

        The data you receive from encode_photo_data() is not a file, so you have to use Photo(-data=>...):

        $encoded_pic = encode_photo_data("up.bmp"); my $pic = $top->Photo(-data=>$encoded_pic);
        or in one line:
        my $pic = $top->Photo(-data=>encode_photo_data("up.bmp"));
        Regards, mawe