Here's a code sample to display animated GIF's using ImageMagick
?. It's fairly crude, but it should help you get started.
use Win32::GUI;
use Win32::GUI::DIBitmap;
use Image::Magick;
use strict;
use warnings;
my $anifile = shift;
die "You must supply a gif file" if !defined $anifile;
my $currentframe = 0;
my $image = Image::Magick->new();
my $result = $image->Read($anifile);
die $result if $result;
my $coalesce = $image->Coalesce();
my $framecount = $#$image;
my $height = $coalesce->[0]->Get('height');
my $width = $coalesce->[0]->Get('width');
my @frames;
my $delay = $image->[0]->Get('delay');
push @frames, getFrameAsBmp(0);
print "Animation file: $anifile\n";
print "Height: $height\n";
print "Width: $width\n";
print "Framecount: $framecount\n";
print "Delay: $delay\n";
my $W = new Win32::GUI::Window(
-title => "Animated GIF Test",
-pos => [100, 100],
-height => $height + 50,
-width => $width + 2,
-name => 'Window',
);
my $lbl = $W->AddLabel(
-top => 10,
-left => 1,
-height => $height,
-width => $width,
-bitmap => $frames[0],
-name => 'Animation',
-visible => 1,
);
$W->AddTimer('T1', $delay * 10);
$W->Show();
Win32::GUI::Dialog();
sub Window_Terminate {
-1;
}
sub getFrameAsBmp {
my $frameno = shift;
my @frame = $coalesce->[$frameno]->ImageToBlob();
my $dib = newFromData Win32::GUI::DIBitmap($frame[0]);
my $bmp = $dib->ConvertToBitmap();
return $bmp;
}
sub T1_Timer {
$currentframe = 0 if $currentframe > $framecount;
push @frames, getFrameAsBmp($currentframe) if !defined $frames[$currentframe];
$lbl->SetImage($frames[$currentframe++]);
}