BTA Flexing

My passion RIAs…………..Shardul Singh Bartwal

Saving Image to File System Using Flex 4

Posted by Shardul Singh Bartwal on July 4, 2010

It is possible for us to saving any image to our computer from flex application( without any server code).Below is
the demo application.Please not that this is the feature of the flash player 10. So It will not work if your flash player is
older than flash player 10.


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
 xmlns:s="library://ns.adobe.com/flex/spark"
 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
 <fx:Script>
 <![CDATA[

 import mx.graphics.ImageSnapshot;
 import mx.graphics.codec.JPEGEncoder;
 private function saveImageToFileSystem():void
 {
 var jPEGEncoder:JPEGEncoder = new JPEGEncoder(500);
 var imageSnapshot:ImageSnapshot = ImageSnapshot.captureImage(imgCanvas, 0, jPEGEncoder);
 var fileReference:FileReference = new FileReference();
 fileReference.save(imageSnapshot.data, "img123.jpg");
 }
 ]]>
 </fx:Script>

<mx:VBox horizontalAlign="center" verticalAlign="middle">
<mx:Canvas id="imgCanvas">
<mx:Image source="images/image1.jpg"/>
</mx:Canvas>
 <s:Button click="saveImageToFileSystem()" label="Save Image"/>
</mx:VBox>


</s:Application>




Advertisements

4 Responses to “Saving Image to File System Using Flex 4”

  1. Chris said

    How would this work for multiple images? E.g. the user clicks the button once and N different images are downloaded to the same destination?

    • shardulbartwal said

      This will not work for multiple images at one time according to the Security measures of the flash player.This feature is totally different from the download.
      And for every file one will require the human interaction by clicking on a button.

  2. Christian said

    The example above specifies a quality parameter of 500. According to the current documentation, “Parameters – quality:Number (default = 50.0) — A value between 0.0 and 100.0. The smaller the quality value, the smaller the file size of the resultant image. The value does not affect the encoding speed. Note that even though this value is a number between 0.0 and 100.0, it does not represent a percentage. The default value is 50.0.” Helpful post though. Very grateful.

  3. twitxr.com said

    It’s going to be ending of mine day, but before end I
    am reading this wonderful article to improve my experience.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: