Skip to main content
hellojohnny
Participant
September 6, 2011
Question

How to Save Full Resolution Image Back to CameraRoll (Android)

  • September 6, 2011
  • 1 reply
  • 1929 views

Device: Nexus One

OS: Android 2.3.4

Class: CameraRoll

Error: [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error." errorID=2038]

I'm trying to develop a photo app but am having problems saving the full sized version of the image back to the CameraRoll.  This is very frustrating as I've only seen examples saving the stage to CameraRoll (which I can get to work).

Is there a limitation to saving back to CameraRoll??  When I try to load an image (2592 x 1944) and save it directly back to CameraRoll using addBitmapData(), I get the following error.

[ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error." errorID=2038]

Here's a code sample.

// class vars for CameraRoll and Loader

private var _cameraRoll:CameraRoll = new CameraRoll();

private var _loader:Loader = new Loader();


// launch _cameraRoll

private function launchCameraRoll(e:MouseEvent):void {

     _cameraRoll.addEventListener(MediaEvent.SELECT, loadImg);

     _cameraRoll.browseForImage();

}


// open selected image using _loader

private function loadImg(e:MediaEvent):void {

     if (e.data.isAsync) {

          _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadImgError);

          _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, saveImage);

          _loader.loadFilePromise(e.data);

     } else {

          _loader.loadFilePromise(e.data);

          saveImage();

     }

}


// once loaded, save image immediately back to _cameraRoll

private function saveImage(e:Event = null):void {

     _cameraRoll.addEventListener(ErrorEvent.ERROR, onError);

     _cameraRoll.addEventListener(Event.COMPLETE, onComplete);

    

     var bmd:BitmapData = new BitmapData(_loader.width, _loader.height);    

     bmd.draw(_loader);

    

     _cameraRoll.addBitmapData(bmd);

}

// trace error

private function onError(e:ErrorEvent):void {

     trace(e);          // [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error." errorID=2038]

}

// show complete status

private function onComplete(e:Event):void {

     trace("complete");

}

This topic has been closed for replies.

1 reply

Inspiring
September 7, 2011

Found this in the AIR 2.5 release notes known issues :

Saving a very large bitmap data (4000x2000 size) using CameraRoll.addBitmapData() causes crash (2712034)

May be it's not resolved... and crash even at 2000 x 2000 :S

Participant
September 7, 2011

Yes, I have the same problem.

And, what is the bigger size allowed by the camera roll?

There are another way to save big images with air 2.5?

Inspiring
September 7, 2011

On android you could save it to the sdcard using the File class. On iOS, i don't think so.