Saturday, September 05th, 2009 | Author: Dave

Here’s a nice little tip for smoothing bitmaps when you’re loading them from an external source. Let’s say you use something like so to load a client logo:

var logoLoader = new Loader();
addChild(logoLoader);
logoLoader.load(new URLRequest("myUrl/myFile.jpg"));
logoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, logoComplete);

When the jpg has loaded, logoComplete will be called – you can smooth the image using:

function logoComplete(e:Event):void 
{	
	//smooth loaded image	
	var bit:Bitmap = e.target.content;
	if(bit != null){
		bit.smoothing = true;
	}
 
	//resize to fit grid squares
	bit.width = bit.height = SQUARE_SIZE;
 
	//fade in
	TweenLite.from(bit, 1, { alpha:0 } );
}

This can be especially handy if you’re resizing the image by setting its width and height, as shown here.
girl_sample
Here’s a sample of loading an identical 150×150 jpeg image and then resizing to 300×300 with the above code. The one on the left has the bit.smoothing = true; line commented out.

Category: as3
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.