in reply to Bitmap for beginners (Perl Tk)

Since you are a beginner, and the topic is bitmaps, I will tell you a few pointers to help you understand Tk images.

1. Almost all "images" in Tk must be converted to "Photo objects" before they can be used, as in the example given to you. There are a few exceptions, like XPM files, which can be read in as Pixmaps. But Tk comes with built-in support for png, jpg, and gifs, but you may need to load the modules like "use Tk::JPEG;" or "use Tk::PNG;".

2. If you are reading data into a photo object from "memory" as opposed to from a file, you must base64 encode the image first.


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Bitmap for beginners (Perl Tk)
by TonyDonker (Novice) on Feb 16, 2005 at 08:30 UTC
    Hi zentara,

    when trying to load a .jpg with the following:

    use Tk;
    use Tk::JPEG;
    my $top = new MainWindow;
    my $pic = $top->Photo(-file=>"arrow.jpg");
    $top->Button(-image=>$pic)->pack();
    MainLoop();

    I receive the message:

    Can't locate Tk/JPEG.pm in @INC (@INC contains:
    E:/Perl/lib E:/Perl/site/lib .)
    at E:\As2ConGUI\work\bitmap.pl line 2.
    BEGIN failed--compilation aborted at
    E:\As2ConGUI\work\bitmap.pl line 2.

    I have installed the correct Perl extensions...

    Thanks,

    Ton
      I use linux, and your code works, except for one thing...'arrow.jpg' is not in the current directory. So I don't know what your windows problem is. I would guess that you have an old perl version, and you need to get Tk::JPEG as a separate ppm(it's standard in the newer Perl versions). Also, unless 'arrow.jpg' is a file in the current script directory, you will need to specify the full path to it, or use something like:
      (-file => Tk->findINC('arrow.jpg'))

      I'm not really a human, but I play one on earth. flash japh