Try:
private function getBitmapData(target:Image):BitmapData
var bm:Bitmap = target.content as Bitmap;
var bmData:BitmapData = bm.bitmapData;
return bmData;
}
----- Original Message -----
From: "Daniel Tse" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, April 11, 2008 11:41 PM
Subject: [flexcoders] JPGEncoding of mx:Image
> 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/
> -------------
>
------------------------------------
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/