hi all,
i did the following code which is running properlly,but i want 1 more
thing which i'm notgetting how to do it.
User can save img at any folder but once he did this,  next time when
user is browse to save again , i want to show last save folder at
browse by user.But here it always going to default path when user
browse to save as image.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml";
        layout="vertical" backgroundGradientAlphas="[1.0, 1.0]"
        backgroundGradientColors="[#FFFFFF, #C0C0C0]"
        width="400" height="350"
        creationComplete="init()">
        <mx:Script>
                <![CDATA[
                        import mx.controls.Alert;
                        import mx.core.Application;
                        import flash.display.BitmapData;
                        import mx.graphics.codec.JPEGEncoder;
                        import mx.graphics.codec.PNGEncoder;
                        import mx.collections.ArrayCollection;
                        import mx.core.UIComponent;

                        //Format to save the image
                        public static const FORMAT_JPEG:uint = 0x00;
                        public static const FORMAT_PNG:uint = 0x01;

                        //Extensions for the file
                        private static const EXT_JPEG:String = ".jpg";
                        private static const EXT_PNG:String = ".png";

                        //Choose the a directory in user's document folder to 
store the
images
                        //private static const IMAGE_FOLDER:String = 
"SaveWebcam/images/";
                        private var IMAGE_FOLDER:String ;

                        //Inits the webcam
                        private function init():void{

                        }

                        //Saves the image snapshot in specified format
                        private function 
saveImage(comp:DisplayObject,format:uint):void{
                                //Bitmapdata from the component to take snapshot
                                var bmpd:BitmapData = new 
BitmapData(comp.width,comp.height);
                                bmpd.draw(comp);
                                //Bytearray of the final image
                                var imgByteArray:ByteArray;
                                //extension to save the file
                                var ext:String;
                                //verify specified format and use the correct 
encoder to produce
the bytearray
                                switch(format){
                                        case FORMAT_JPEG:
                                                ext = EXT_JPEG;
                                                var jpgenc:JPEGEncoder = new 
JPEGEncoder(80);
                                                imgByteArray = 
jpgenc.encode(bmpd);
                                                break;
                                        case FORMAT_PNG:
                                                ext = EXT_PNG;
                                                var pngenc:PNGEncoder = new 
PNGEncoder();
                                                imgByteArray = 
pngenc.encode(bmpd);
                                                break;
                                }
                                //gets a reference to a new empty image file
                                var fl:File = getNewImageFile(ext);
                                fl.addEventListener(Event.SELECT,function() 
{dirSelected
(fl,imgByteArray);},false);
                                //fl.addEventListener(Event.SELECT, 
dirSelected);
                fl.browseForSave('a.png');
                                //fl.resolvePath('D:/');
                                //Use a FileStream to save the bytearray as 
bytes to the new file
                                var fs:FileStream = new FileStream();
                                try{
                                        //open file in write mode
                                        fs.open(fl,FileMode.WRITE);
                                        //write bytes from the byte array
                                        fs.writeBytes(imgByteArray);
                                        //close the file
                                        fs.close();
                                }catch(e:Error){
                                        trace(e.message);
                                }
                        }

                        function 
dirSelected(fl:File,imgByteArray:ByteArray):void {
                var fs:FileStream = new FileStream();
                                try{
                                        fs.open(fl,FileMode.WRITE);
                                        fs.writeBytes(imgByteArray);
                                        fs.close();
                                }catch(e:Error){
                                        trace(e.message);
                                }
}

                        //Returns a unique new image file reference
                        //with specified extension
                        private var file:File;
                        private function getNewImageFile(ext:String):File{
                                //Create a new unique filename based on 
date/time
                                var fileName:String = 
"image"+getNowTimestamp()+ext;
                            var fl:File = 
File.documentsDirectory.resolvePath(IMAGE_FOLDER
+fileName);
                                if(fl.exists){
                                        //if exists , tries to get a new one 
using recursion
                                        return getNewImageFile(ext);
                                }
                                return fl;
                        }
                        //Returns a string in the format
                        //200831415144243
                        private function getNowTimestamp():String{
                                var d:Date = new Date();
                                var tstamp:String = 
d.getFullYear().toString()+d.getMonth()
+d.getDate()+d.getHours()+d.getMinutes()+d.getSeconds()
+d.getMilliseconds();
                                return  tstamp;
                        }

                        //Handler for the save button click
                        private function onClickSave():void{
                          saveImage(camVideo,FORMAT_PNG);
                        }
                ]]>
        </mx:Script>

        <mx:Label text="Save your picture" fontSize="14" color="#000000"
fontWeight="bold"/>
        <!--<mx:VideoDisplay id="camVideo2" width="320" height="240" />-->
        <mx:Canvas id="camVideo" width="100%" height="100%" >
                <mx:Label text="canvas" />
        </mx:Canvas>
        <mx:Button id="save_btn" label="Click to save a snapshot" width="181"
click="onClickSave()"/>

</mx:WindowedApplication>

thank you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to