Where can I save the image?

How to save Image with its original size?

  • In my Flex application I load an image into the Image control. After loading the image I can apply filters like color transform or grayscale etc and then I want to save the image with the filter applied. I am having trouble saving the image with the filters applied. With the following code the Image gets saved without the filters. However, if I use finalImagedata = ImageSnapshot.captureBitmapData(myImage); Then the image gets saved with filters applied but with the dimension of the image control. I want to save the image with its original dimension. To be clear, if the image is 1000px X 1000px and displayed in a 300px X 300px image control, while saving I still want to save the image with 1000px X 1000px dimesnion. How to do that? I have also tried to get BitmapData directly from the image control content like below but that doesn't seemt to work. Any help guys? finalImagedata = Bitmap(myImage.content).bitmapData; var filtersArray:Array = new Array; private var finalImagedata:BitmapData; private function loadImage(url:String):void { var request:URLRequest = new URLRequest(url); var imageLoader:Loader = new Loader(); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_completeHanlder); imageLoader.load(request); } private function image_completeHanlder(event:Event):void { var bmd:BitmapData = Bitmap(event.currentTarget.content).bitmapData; var bmpMy:Bitmap = new Bitmap(bmd); myImage.data=bmpMy; } protected function button1_clickHandler(event:MouseEvent):void { loadImage("http://localhost/main/image.jpg"); } protected function prepareFinalImage():void { finalImagedata = new BitmapData(myImage.content.width, myImage.content.height, true); finalImagedata.draw (myImage.content); } protected function btnSave_clickHandler(event:MouseEvent):void { prepareFinalImage(); var encoder:Object = new Object(); var defaultName:String; var je:*; je = new JPGEncoder(100); encoder.encode = je.encode; defaultName = "myImage.jpg"; var imageBytes:ByteArray = encoder.encode(finalImagedata); var fr:FileReference = new FileReference(); fr.save(imageBytes,defaultName); } protected function btnGrayScale_clickHandler(event:MouseEvent):void { var red:Number = 0.3086; // luminance contrast value for red var green:Number = 0.694; // luminance contrast value for green var blue:Number = 0.0820; // luminance contrast value for blue var cmf1:ColorMatrixFilter = new ColorMatrixFilter([red, green, blue, 0, 0, red, green, blue, 0, 0, red, green, blue, 0, 0, 0, 0, 0, 1, 0]); filtersArray.push(cmf1); myImage.filters = filtersArray; }

  • Answer:

    You should store the bitmapdata retrieved from the Loader as a class member: private var bmd:BitmapData; [...] private function image_completeHanlder(event:Event):void { bmd = Bitmap(event.currentTarget.content).bitmapData; var bmpMy:Bitmap = new Bitmap(bmd); myImage.data=bmpMy; } and your prepareFinalImage method should rely on the loaded bitmapdata: protected function prepareFinalImage():void { finalImagedata = new BitmapData(bmd.width, bmd.height, true); if (myImage.filters.length > 0) finalImagedata.applyFilter(bmd, new Rectangle(0, 0, bmd.width, bmd.height), new Point(0,0), myImage.filters[0] as BitmapFilter); if (myImage.filters.length > 1) for (var i:int = 1; i < myImage.filters.length; i++) { finalImagedata.applyFilter(finalImagedata, new Rectangle(0, 0, bmd.width, bmd.height), new Point(0,0), myImage.filters[i] as BitmapFilter); } } This way you would apply the filters on the BitmapData not on the scaled DisplayObject.

redGREENblue at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.