Hi,
I'm trying to capture a loaded image into mx:Image. I'm able to sort of
write the bitmapdata of an image to a file except when I load an image that
is larger than the image holder, the image holder resizes the image so it
fits but when I write it out I don't get what I see instead I get a cropped
section of the image. So instead of seeing "test.jpg" as a resized version
of the image I've loaded I get the image cropped at 100%
I have a method like the following (with an mx:Image named imgHolder).
//Encoding
import mx.graphics.codec.JPEGEncoder;
import com.adobe.images.JPGEncoder;
//Local File System
import flash.desktop.*;
import flash.filesystem.File;
private function saveLoadedImage():void {
var loJPGEncoder:JPGEncoder = new JPGEncoder();
var bd: BitmapData =
getBitmapData(mx.core.Application.application.imgHolder); //something not
quite right as it crops and doesn't resize.
var encodedJPG:ByteArray = loJPGEncoder.encode(bd);
var file:File = File.desktopDirectory.resolvePath("test.jpg");
//saves it to the desktop as a file labeled "test.jpg"
var stream:FileStream = new FileStream();
stream.open( file, FileMode.WRITE );
stream.writeBytes( encodedJPG );
trace("saved.");
}
private function getBitmapData( target : UIComponent ) : BitmapData
{
var bd : BitmapData = new BitmapData( target.width,
target.height );
var m : Matrix = new Matrix();
bd.draw( target, m );
return bd;
}
Any insight? Thanks!
-Daniel
--
-------------
e: [EMAIL PROTECTED]
w: http://DanielTse.com/
-------------