Posted By

rfeldmesser on 11/12/10


Tagged

resizebitmapData rescaleas3


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

onemanstudio
alptugan
burnandbass
thastyle
liakwee


resize bitmapdata


 / 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.

  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  

You need to login to post a comment.