Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm using the below perl code fragment to load many transparent png files into a single swf object. I think I must be mucking up the alpha level in my conversion somewhere, because the transparencies are being lost. A little help please, am I making the mistake in perl, imagemagik or swf formatting ?
my $image = Image::Magick->new; $image->Read("image_piece03.png"); my $width = 16; my $height = 16; my $lossless; $lossless = SWF::Element::Tag::DefineBitsLossless->new( CharacterID => 1, BitmapFormat => 5, BitmapWidth => $width, BitmapHeight => $height, ); my $d = deflateInit() or die "Can't open zlib stream."; for(my $y = 0; $y<$height; $y++) { for(my $x = 0; $x<$width; $x++) { my @rgba = split /,/, $image->Get("pixel[$x,$y]"); $rgba[3] = 255-$rgba[3]; @rgba=@rgba[3,0..2]; my ($output, $status) = $d->deflate(pack('CCCC',@rgba)); # 4 b +ytes per pixel. die "Compress error." unless $status == Z_OK; $lossless->ZlibBitmapData->add($output); } } my ($output, $status) = $d->flush(); die "Compress error." unless $status == Z_OK; $lossless->ZlibBitmapData->add($output); $lossless->pack($new);

Replies are listed 'Best First'.
Re: Perserving transparency png into swf
by almut (Canon) on Dec 13, 2007 at 09:28 UTC

    Haven't tried it, but the documentation suggests that DefineBitsLossless2 might be the right class:

    Tag::DefineBitsLossless / Tag::DefineBitsLossless2
    
         defines a loss-less bitmap. DefineBitsLossless2 contains alpha channels