开发者

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

  • Device - Nexus One
  • OS - Android 2.3.4
  • Class - CameraRoll
  • Method - addBitmapData()
  • 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();
}

// o开发者_开发技巧pen selected image using _loader
private function loadImg(e:MediaEvent):void {
     if (e.data.isAsync) {
          _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");
}


I had the same problem (even with real small images).
I solved it by uncommenting this line in the <android><manifestAdditions> section of the [Application]-app.xml file:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


have you tried to save image in lower res? e.g. 1024x768? Maybe there is a limitation on the size that your device supports, I've found this or maybe the disk space is problem like mentioned here

best regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜