R
Richard Trahan
Consider the following sub. On entry, $tl is a Toplevel, $rmn is an
index into an array of Archive::Zip object member names; comments
explain the others.
sub display_image
{
my ($tl,$rmn) = @_; # Toplevel, requested member number
my $mnref = $tl->{'member_names'}; # ref to member names array
my $zip = $tl->{'zip'}; # Archive::Zip object
my $membername = $mnref->[$rmn];
my $member = $zip->memberNamed($membername);
$tl->{'current_member_number'} = $rmn; # reset current member
my $fh;
my $fn = "C:/windows/temp/temp.jpg";
open $fh,">",$fn;
$member->extractToFileHandle($fh); # this works ok
close $fh;
# my $contents = $zip->contents($member); # (binary) jpeg data
# open $fh,">","C:/temp/temp2.jpg";
# binmode $fh;
# print $fh $contents; # this works ok
# close $fh;
my $image = $tl->Photo(
'-format' => 'jpeg',
# -data => $contents, # this doesn't work
-file => $fn, # this works ok
);
my $button = $tl->{'button'}; # button where image is displayed
$button->configure(-image => $image); # set image
$tl->configure(-title => $tl->{'file_name'} .
":" . $tl->{'sequence'} . " - $membername");
}
Commented sections show that I can successfully extract the "contents"
of a Zip::Archive member (all of which are jpeg files), and write it to
a file (it displays perfectly in a browser, PhotoEditor, etc.). I can
also "extract" that member to another file and specify that file name to
the Photo object, whereupon it displays just fine. But when I take the
"contents", which is supposed to be pure jpeg binary data, and feed it
to the Photo object, the system complains that it doesn't recognize the
file format.
Any help, please.
index into an array of Archive::Zip object member names; comments
explain the others.
sub display_image
{
my ($tl,$rmn) = @_; # Toplevel, requested member number
my $mnref = $tl->{'member_names'}; # ref to member names array
my $zip = $tl->{'zip'}; # Archive::Zip object
my $membername = $mnref->[$rmn];
my $member = $zip->memberNamed($membername);
$tl->{'current_member_number'} = $rmn; # reset current member
my $fh;
my $fn = "C:/windows/temp/temp.jpg";
open $fh,">",$fn;
$member->extractToFileHandle($fh); # this works ok
close $fh;
# my $contents = $zip->contents($member); # (binary) jpeg data
# open $fh,">","C:/temp/temp2.jpg";
# binmode $fh;
# print $fh $contents; # this works ok
# close $fh;
my $image = $tl->Photo(
'-format' => 'jpeg',
# -data => $contents, # this doesn't work
-file => $fn, # this works ok
);
my $button = $tl->{'button'}; # button where image is displayed
$button->configure(-image => $image); # set image
$tl->configure(-title => $tl->{'file_name'} .
":" . $tl->{'sequence'} . " - $membername");
}
Commented sections show that I can successfully extract the "contents"
of a Zip::Archive member (all of which are jpeg files), and write it to
a file (it displays perfectly in a browser, PhotoEditor, etc.). I can
also "extract" that member to another file and specify that file name to
the Photo object, whereupon it displays just fine. But when I take the
"contents", which is supposed to be pure jpeg binary data, and feed it
to the Photo object, the system complains that it doesn't recognize the
file format.
Any help, please.