I replicated your error with your code. I looked at the test suite for Tk in the t/photo.t, and they include use Tk::PNG; use Tk::JPEG; (or equivalent conditional require's), so I successfully tried code with the two extra use statements:
use strict; use warnings; use Tk; use Tk::PNG; use Tk::JPEG; my @arr; push @arr, { name => 'sample.gif', type => 'image/gif'}; push @arr, { name => 'sample.png', type => 'image/png'}; push @arr, { name => 'sample.jpg', type => 'image/jpeg'}; foreach my $fh (@arr) { my $f = $fh->{name}; my $t = $fh->{type}; eval { my $mw = MainWindow->new; my $lbl = $mw->Label; my $photo = $mw->Photo(-file=>$f); #, -format=>$t ); $lbl->configure(-image=>$photo); $lbl->pack; MainLoop; 1; } or do { warn "here: $@\n"; }; }
update: I was curious about the -format, since the mime-types I had tried (based on commented-out code) didn't work. the t/photo.t showed method $photo->formats(), so I printed those => jpeg, png, bmp, xpm, xbm, gif, PPM. So, to get -format to work with my code, it should be as follows (which still works):
use strict; use warnings; use Tk; use Tk::PNG; use Tk::JPEG; my @arr; push @arr, { name => 'sample.gif', type => 'gif'}; push @arr, { name => 'sample.png', type => 'png'}; push @arr, { name => 'sample.jpg', type => 'jpeg'}; foreach my $fh (@arr) { my $f = $fh->{name}; my $t = $fh->{type}; eval { my $mw = MainWindow->new; my $lbl = $mw->Label; my $photo = $mw->Photo(-file=>$f, -format=>$t ); print join ", ", $photo->formats(), "\n"; $lbl->configure(-image=>$photo); $lbl->pack; MainLoop; 1; } or do { warn "here: $@\n"; }; }
In reply to Re: Displaying PNG and JPG images using Tk on Windows
by pryrt
in thread Displaying PNG and JPG images using Tk on Windows
by skleblan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |