Return to Snippet

Revision: 35759
at November 12, 2010 23:16 by rfeldmesser


Initial Code
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);
		}

Initial URL

                                

Initial Description
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.

Initial Title
resize bitmapdata

Initial Tags

                                

Initial Language
ActionScript 3