Resizing bitmap images with Actionscript 3.0
Hey, I just did a quick experiment with bitmaps in AS3. Nothing fancy, I just loaded in an external JPEG, resized it into 3 different sizes and then drew them to stage. I’m sure someone can use this. For now, everything is hard-coded and the code is right in the .FLA. Maybe I’ll try and make a nice class out of this, although I’m sure there’s already one out there. Anyway, check out the code or download the FLA.
var mediaLoader:Loader = new Loader(); var bmFullsize:Bitmap; var bmHalfsize:Bitmap; var bmThumbsize:Bitmap; mediaLoader.load(new URLRequest("ostrich.jpg")); mediaLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, resizeImages); function resizeImages(e:Event):void { bmFullsize = new Bitmap(e.target.content.bitmapData.clone()); bmHalfsize = new Bitmap(e.target.content.bitmapData.clone()); bmThumbsize = new Bitmap(e.target.content.bitmapData.clone()); bmFullsize.width = 300; bmFullsize.height = 300; bmFullsize.smoothing = true; bmHalfsize.width = 150; bmHalfsize.height = 150; bmHalfsize.x = bmFullsize.width; bmHalfsize.smoothing = true; bmThumbsize.width = 75; bmThumbsize.height = 75; bmThumbsize.x = (bmFullsize.width + bmHalfsize.width); bmThumbsize.smoothing = true; showImages(); } function showImages():void { addChild(bmFullsize); addChild(bmHalfsize); addChild(bmThumbsize); }
June 3, 2008 | Filed Under Actionscript, Flash
Comments
Leave a Reply
