3/30/2010 8:44:22 PM
Title:
Save image using FileReference
Hi..
Is there any way that I can change the default filetype from *.* jpg when im saving an image?
var imageFile:FileReference = new FileReference();
imageFile.save(jpgStream,"BarGraph.jpg");
Thanks....
3/30/2010 11:15:22 PM
you can save image to any format using the required encode , for example if you want to save to png you can encode your bmp data to png using pngEncoder class and save it in adobe air. Remember to provide the image data as raw data to variable "myBitmapData";
import mx.graphics.codec.PNGEncoder;
//captured bitmap from loaded image in image component with id myLoadedImage
var myBitmapData:BitmapData = new BitmapData(myLoadedImage.width,myLoadedImage.height);
var imageFile:FileReference = new FileReference();
var png_encoder:PNGEncoder = new PNGEncoder();
var encodedByteArray:ByteArray = png_encoder.encode(myBitmapData);
//Save method is supported by Adobe AIR only
//if using flex then send the encodedByteArray to web server using post for saving
imageFile.save(encodedByteArray,"BarGraph.png");
6/15/2010 12:06:05 AM
Hi Dave,
From the above code , how to use in my mxml application?
Please give the overview of the above code. How to use in my mxml code, It's urgent for me, please help me?
Thanks & Regards,
K.V.Ramakrishna.
6/15/2010 1:13:25 AM
you can load the image in the image component in the mxml and give id "myLoadedImage" to image component. You can load your jpg file using source property of image component.
then call the above code in a button click function.
One thing you must note that the last line to save it as file only works for Adobe AIR application only. If you want to save this application in a flex webapplication the you need to send the encodedByteArray to server and save image using php or .net script
To save using server side see these examples
http://www.sephiroth.it/tutorials/flashPHP/amfphp_bytearray/index.php
http://www.zedia.net/2008/sending-bytearray-and-variables-to-server-side-script-at-the-same-time/