Hi. I need some help with displaying a JPEG via TK using ActiveState Perl.
Pulling the image from a file works fine:
use strict;
use Tk;
use Tk::JPEG;
my $fname = "rock.jpg";
my $win = new MainWindow;
my $image = $win->Photo('-format' => 'jpeg',
'-file' => $fname);
$win->Label(-image=>$image)->pack;
MainLoop;
But I can seem to load images from a data string (as the images will eventually be pulled from a database). That is,
this doesn't work:
use strict;
use Tk;
use Tk::JPEG;
my $fname = "rock.jpg";
open(F, $fname) or die "cant open $fname";
binmode(F);
undef $/;
my $jpeg = <F>;
close(F);
my $win = new MainWindow;
my $image = $win->Photo('-format' => 'jpeg',
'-data' => $jpeg);
$win->Label(-image=>$image)->pack;
MainLoop;
It dies with this error:
couldn't recognize image data at C:/Perl/site/lib/Tk/Image.pm line 21.
Can anyone offer advice? Am I reading the JPEG in wrong, or am I sending it to TK wrong?
Thanks
nop