create a thumbnail of an image in actionscript

34 sec read

Assume test1.jpg is the original file and test1_thumb.jpg is the thumbnail file to be created. The width or height of the thumbnail is of maximal size 100.

private function loadBMP():void
	loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
	loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

    var request:URLRequest = new URLRequest(File.desktopDirectory.resolvePath("test1.jpg").url);
private function onComplete(e:Event):void
	var thumbSize:int = 100;
	var ratio:Number = 1;
	if(loader.width >= loader.height)
		ratio = thumbSize/loader.width;
		ratio = thumbSize/loader.height;
	} = new BitmapData( loader.width*ratio, loader.height*ratio, false);
	var matrix:Matrix = new Matrix();
	matrix.scale(ratio, ratio); loader.content, matrix );
	var jpg:JPEGEncoder = new JPEGEncoder();
	var ba:ByteArray = jpg.encode(;
	var f:File = File.desktopDirectory.resolvePath("test1_thumb.jpg");
	var fs:FileStream = new FileStream();, FileMode.WRITE);
private function onIOError(e:IOErrorEvent):void
	trace('error happened');

Receive email notification via email 博客有新内容通知我

Don't want to miss new papers in your field? Check out Stork we developed:

How much money did I make from an app?

Undoubtedly some people are very successful in making money by developing a smartphone app. Back in 2012 I developed an app called “Handbook of...
Xu Cui
27 sec read

Handy programs to visualize NIRS data (2): plotTopoMap

Often you need to view the spatial pattern of activation as in the example below. plotTopoMap allows you to do that. It probably only...
Xu Cui
37 sec read

Flash 3D video demo

Racer Ostrova Zombie
Xu Cui
0 sec read

One Reply to “create a thumbnail of an image in actionscript”

Leave a Reply

Your email address will not be published. Required fields are marked *