in reply to how to free memory allocated for Tk::Photo?
All you need to do is add the -shrink option on the read and the width and height will be set correctly. You don't even need the blank. In a quick test (under win32) it appears that memory is returned to the system when a small image is read after a large one.
use Tk; use Tk::JPEG; use File::Glob ':glob'; my @jpgs = bsd_glob('*.jpg'); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $image = $mw->Photo(-format => 'jpeg', -file => $jpgs[$index]); my $b = $mw->Button( -image => $image )->pack(); $mw->after(1000, \&next_image); MainLoop; sub next_image { $image->read( $jpgs[$index], -shrink ); $b->configure(-image => $image); $mw->configure( -title => sprintf "$jpgs[$index] [%dx%d]", $image->width, $image->height ); $mw->after(1000, \&next_image) if (++$index <= $#jpgs); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: how to free memory allocated for Tk::Photo?
by pg (Canon) on Oct 29, 2004 at 15:24 UTC | |
Re^2: how to free memory allocated for Tk::Photo?
by pg (Canon) on Oct 29, 2004 at 14:53 UTC |