M Studio Labs Beaker

M Studio Labs


Webby 09

Here’s a little utility that allows you to batch-resize or crop images and output as JPG — along with the source code. If you’re not familiar with AIR, you just need to download AIR first before you download & install the Image Resizer:

Download Adobe AIR here

Download the AIR Image Resizer here

Download the source files here

Also a few notes that might be of interest to developers:

For developers working in Eclipse/Flex: there is an ANT build file in the root directory of the .zip. Be sure to update “build.properties” with the location of your Flex SDK and project directory. Also, be sure to add “lib.swc” to your classpath.

For developers working in Flash: You can publish “build.fla”, but be sure to add “com.Main” as your document root.

If you’re trying to resize a display object’s bitmap for output, you can use the Matrix class. Let’s say we want to resize “target_mc” to 50% of it’s width and height:

var matrix : Matrix = new Matrix();
matrix.scale(.5, .5);
var bmp : BitmapData = new BitmapData(target_mc.width * .5, target_mc.width * .5, true);
bmp.draw(_target_mc, matrix);
// if you just want to crop the image from the upper-left, you'd leave off the matrix param:
bmp.draw(_target_mc);

If you want to save an image as a JPG or PNG from Flash, you” first need to grab corelib from Google Code.

You can pass an image’s bitmapData to the encoder and then write the file using FileStream. For example, we want to save “target_bmd” BitmapData as a JPEG named “output.jpg” in the user’s “Documents” folder:

var jpgEncoder : JPGEncoder = new JPGEncoder(100); // this param is the JPG quality from 0-100         
var jpg : ByteArray = jpgEncoder.encode(target_bmd);
var stream : FileStream = new FileStream();
var file : File = File.documentsDirectory.resolvePath("output.jpg");
stream.open(file, FileMode.WRITE);
stream.writeBytes(jpg, 0, jpg.length);
stream.close();

Leave a Reply




Comment:





About this Blog
This blog is maintained by Alex Motzenbecker at M Studio. This is where I'll try to share our approaches to Flash-related challenges with the rest of the developer community.

I'll post our solutions, any Flash-related news and updates on the work we're doing here. You can send any feedback or hello's to alex [at] mstudio.com.
spacer
Recent Posts
Categories
Favorite Resources