/ Published in: ActionScript 3
This snippet uses the BitmapUtil to resize bitmap data, whilst maintaining transparency and aspect ratio, It assumes that you want a square output, so for those of you who want resizing rectangular images, just make the "ratio" part handle both X and Y.
cheers.
cheers.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static function resizeBitmapData(bmp: BitmapData, _tileSize:int):BitmapData { var image : mx.controls.Image = new mx.controls.Image(); image.load (new Bitmap (bmp, "auto", true)); var ratio:Number; if(image.content.width>image.content.height) { ratio = _tileSize/image.content.width; } if(image.content.width<image.content.height) { ratio = _tileSize/image.content.height; } image.content.width *= ratio; image.content.height *= ratio; return BitmapUtil.getSnapshot(image); }