resize bitmapdata


/ Published in: ActionScript 3
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. public static function resizeBitmapData(bmp: BitmapData, _tileSize:int):BitmapData
  2. {
  3. var image : mx.controls.Image = new mx.controls.Image();
  4. image.load (new Bitmap (bmp, "auto", true));
  5. var ratio:Number;
  6.  
  7. if(image.content.width>image.content.height)
  8. {
  9. ratio = _tileSize/image.content.width;
  10. }
  11. if(image.content.width<image.content.height)
  12. {
  13. ratio = _tileSize/image.content.height;
  14. }
  15. image.content.width *= ratio;
  16. image.content.height *= ratio;
  17. return BitmapUtil.getSnapshot(image);
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.