Skip to main content
Inspiring
August 2, 2011
Question

Images saved twice

  • August 2, 2011
  • 2 replies
  • 1100 views

When I use the CameraUI on Android, images are saved twice in the cameraRoll...

Is there a way to prevent that? Or even to prevent it from saving the image at all (I save it in my app storage after a few modifications)?

This topic has been closed for replies.

2 replies

chris.campbell
Legend
August 3, 2011

I haven't played around with the CameraRoll, but I'll give it a try and see what I find on my Android device.  Have you checked out this thread for hints?

http://forums.adobe.com/message/3778496

Chris

RangoraAuthor
Inspiring
August 4, 2011

I did a simple view that will allow you to test.

I did a few test with the same code on each OS.

On an iPad 2, the image isnt saved in the cameraRoll.

On a Playbook, the image is saved once in the cameraRoll.

On a Samsung Galaxy S2 (and a Samsung Galaxy Tab), the image is saved twice in the cameraRoll.

On the Android Emulator, the image is saved once.

On a HTC Desire, the image is saved once.

I hope this will help you to find the problem and solve it!

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark" title="camView">
     
     <fx:Script>
          <![CDATA[
               
               private var imageLoader:Loader;
               private var myCam:CameraUI
               
               protected function button1_clickHandler(event:MouseEvent):void
               {
                    if (CameraUI.isSupported)
                    {
                         imageLoader = new Loader();
                         myCam = new CameraUI();
                         myCam.addEventListener(MediaEvent.COMPLETE, onCameraComplete);
                         myCam.addEventListener(Event.CANCEL, onCameraCancel);
                         myCam.addEventListener(ErrorEvent.ERROR, onCameraError);
                         myCam.launch(MediaType.IMAGE);
                    }
                    else
                    {
                         trace("browse for image not supported");
                    }
               }
               
               protected function onCameraComplete(event:MediaEvent):void
               {     
                    myCam.removeEventListener(ErrorEvent.ERROR, onCameraError);
                    myCam.removeEventListener(MediaEvent.COMPLETE, onCameraComplete);
                    myCam.removeEventListener(Event.CANCEL, onCameraCancel);
                    
                    var imagePromise:MediaPromise = event.data;
                    
                    if( imagePromise.isAsync )
                    {
                         trace( "Asynchronous media promise." );
                         imageLoader = new Loader();
                         imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
                         imageLoader.addEventListener( IOErrorEvent.IO_ERROR, onCameraError );
                         
                         imageLoader.loadFilePromise( imagePromise );
                    }
                    else
                    {
                         trace( "Synchronous media promise." );
                         imageLoader.loadFilePromise( imagePromise );
                         loadedImage();
                    }
                    
               }
               
               protected function onCameraCancel(event:Event):void
               {                    
                    myCam.removeEventListener(ErrorEvent.ERROR, onCameraError);
                    myCam.removeEventListener(MediaEvent.COMPLETE, onCameraComplete);
                    myCam.removeEventListener(Event.CANCEL, onCameraCancel);
                    
               }
               
               protected function onCameraError(event:ErrorEvent):void
               {
                    myCam.removeEventListener(ErrorEvent.ERROR, onCameraError);
                    myCam.removeEventListener(MediaEvent.COMPLETE, onCameraComplete);
                    myCam.removeEventListener(Event.CANCEL, onCameraCancel);
                    
               }
               
               private function asyncImageLoaded( event:Event ):void
               {
                    trace( "Media loaded in memory." );
                    imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, asyncImageLoaded);
                    loadedImage();
               }
               
               private function loadedImage():void
               {
                    var loaded:BitmapData = new BitmapData(imageLoader.content.width, imageLoader.content.height);
                    loaded.draw(imageLoader);
                    myImage.source = loaded;
                    
               }
          ]]>
     </fx:Script>
     
     <fx:Declarations>
          <!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
     </fx:Declarations>
     <s:Button click="button1_clickHandler(event)"/>
     <s:Image id="myImage" x="83" y="139" width="325" height="273"/>
</s:View>

RangoraAuthor
Inspiring
August 8, 2011

Should I fill a bugcase?

RangoraAuthor
Inspiring
August 3, 2011

Bump... Only 4 reads... (3 of them are by me....) Anyone have an idea? Adobe?