header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
khze86
Points:180
Posts:8
Answered

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....



1
Dave
Points: 970
Posts:1
Accepted Answer
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");


2
Ramakrishna
Points: 0
Posts:0
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.

3
Dave
Points: 970
Posts:1
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/


Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 3+6 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions