pg has asked for the wisdom of the Perl Monks concerning the following question:
In the first reply to my slide view of a folder of JPEG's, zentara suggested to use blank() and read() to save memory.
That solution worked great! But now I want not only to view the pictures, but also to process them. In order to do that, the first thing I want to know is the width and height of the picture. I can easily obtain them by calling width() and height(). However with blank() and read(), I don't get the real width and height any more. What happened was that, Tk::Photo extends when a bigger photo is read(), but does not shrink when a smaller one is read, so it reports the biggest width and the biggest height (They are not neccessary to be the width and height of the same picture, as you may have a picture that is super wide, but short, and another one super high, but narrow.)
So I thought there must be a different way to solve the memory issue. I tried couple of things, but all failed. For example (see inline comment):
use Tk; use Tk::JPEG; use File::Glob ':glob'; my @jpgs = bsd_glob('*.jpg'); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $b = $mw->Button()->pack(); $mw->after(1000, \&next_image); MainLoop; sub next_image { $b->configure(-image => undef); #effort to free memory eval { my $image = $mw->Photo(-format => 'jpeg', -file => $jpgs[$index]); $b->configure(-image => $image); $mw->configure(-title => $jpgs[$index]); $image = undef; #effort to free memory #undef($image); effort to free memory }; $mw->after(1000, \&next_image) if (++$index <= $#jpgs); }
Any suggestion?
2004-10-29 Edited by Arunbear: Changed title from 'how to free momery allocated for Tk::Photo?', as per Monastery guidelines
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to free memory allocated for Tk::Photo?
by BrowserUk (Patriarch) on Oct 29, 2004 at 05:47 UTC | |
by pg (Canon) on Oct 29, 2004 at 15:24 UTC | |
by pg (Canon) on Oct 29, 2004 at 14:53 UTC |