Created
September 23, 2011 18:26
-
-
Save caseypugh/1238101 to your computer and use it in GitHub Desktop.
GIFPlayer - How to resize an animated GIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See http://www.bytearray.org/?p=95 | |
// Insert into GIFPlayer.as | |
import flash.geom.Rectangle; | |
public function resize(w:Number, h:Number):void | |
{ | |
for (var i = 0; i < aFrames.length; i++) { | |
aFrames[i].resize(w, h); | |
} | |
} | |
// Insert into GIFFrame.as | |
import flash.geom.Matrix; | |
public function resize(w:Number, h:Number):void | |
{ | |
if (!bitmapData_orig) { | |
bitmapData_orig = bitmapData.clone(); | |
} | |
var m:Matrix = new Matrix(); | |
m.scale(w / bitmapData_orig.rect.width, h / bitmapData_orig.rect.height); | |
var bmd:BitmapData = new BitmapData(w, h, true, 0x000000); | |
bmd.draw(bitmapData_orig, m, null, null, null, true); | |
bitmapData = bmd; | |
} | |
// Example usage | |
var myGIFPlayer:GIFPlayer = new GIFPlayer(); | |
addChild ( myGIFPlayer ); | |
myGIFPlayer.load ( new URLRequest ("animation.gif") ); | |
myGIFPlayer.addEventListener ( GIFPlayerEvent.COMPLETE, function() { | |
myGIFPlayer.resize(400, 300); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Caseypugh
Many thanks for this script to resize
I use this script but some frames of gif animation are breaking
Can you tell what wrong in this ?