Hi,

for a project which I'm developing with cordova i need the possibility
to save the unmodified image from the camera to the photoalbum.

I have attached a patch which implements this new functionality for iOS.

Regards

Stephan Wezel
--- src/ios/CDVCamera.h Tue Oct 08 15:34:33 2013
+++ src/ios/CDVCamera.h Mon Nov 25 13:39:50 2013
@@ -54,6 +54,7 @@
 @property (assign) CGSize targetSize;
 @property (assign) bool correctOrientation;
 @property (assign) bool saveToPhotoAlbum;
+@property (assign) bool saveUnmodifiedImageToPhotoAlbum;
 @property (assign) bool cropToSize;
 @property (strong) UIWebView* webView;
 @property (assign) BOOL popoverSupported;
--- src/ios/CDVCamera.m Tue Oct 08 15:34:33 2013
+++ src/ios/CDVCamera.m Mon Nov 25 13:38:48 2013
@@ -68,6 +68,7 @@
  *  9       saveToPhotoAlbum
  *  10      popoverOptions
  *  11      cameraDirection
+ *  12      saveUnmodifiedImageToPhotoAlbum
  */
 - (void)takePicture:(CDVInvokedUrlCommand*)command
 {
@@ -123,6 +124,7 @@
 
     cameraPicker.correctOrientation = [[arguments objectAtIndex:8] boolValue];
     cameraPicker.saveToPhotoAlbum = [[arguments objectAtIndex:9] boolValue];
+    cameraPicker.saveUnmodifiedImageToPhotoAlbum = [[arguments 
objectAtIndex:12] boolValue];
 
     cameraPicker.encodingType = ([arguments objectAtIndex:5]) ? [[arguments 
objectAtIndex:5] intValue] : EncodingTypeJPEG;
 
@@ -288,7 +290,12 @@
             } else {
                 image = [info 
objectForKey:UIImagePickerControllerOriginalImage];
             }
-
+            
+            if (cameraPicker.saveUnmodifiedImageToPhotoAlbum) {
+                ALAssetsLibrary *library = [ALAssetsLibrary new];
+                [library writeImageToSavedPhotosAlbum:image.CGImage 
orientation:(ALAssetOrientation)(image.imageOrientation) completionBlock:nil];
+            }
+            
             if (cameraPicker.correctOrientation) {
                 image = [self imageCorrectedForCaptureOrientation:image];
             }
@@ -735,5 +742,6 @@
 @synthesize cropToSize;
 @synthesize webView;
 @synthesize popoverSupported;
+@synthesize saveUnmodifiedImageToPhotoAlbum;
 
 @end
--- www/Camera.js       Tue Oct 08 15:34:33 2013
+++ www/Camera.js       Mon Nov 25 13:50:54 2013
@@ -56,11 +56,13 @@
     var allowEdit = !!options.allowEdit;
     var correctOrientation = !!options.correctOrientation;
     var saveToPhotoAlbum = !!options.saveToPhotoAlbum;
+    var saveUnmodifiedImageToPhotoAlbum = 
!!options.saveUnmodifiedImageToPhotoAlbum;
     var popoverOptions = getValue(options.popoverOptions, null);
     var cameraDirection = getValue(options.cameraDirection, 
Camera.Direction.BACK);
 
     var args = [quality, destinationType, sourceType, targetWidth, 
targetHeight, encodingType,
-                mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, 
popoverOptions, cameraDirection];
+                mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, 
popoverOptions, cameraDirection,
+                saveUnmodifiedImageToPhotoAlbum];
 
     exec(successCallback, errorCallback, "Camera", "takePicture", args);
     return new CameraPopoverHandle();

Reply via email to