You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/08/14 22:32:20 UTC

[4/6] git commit: [CB-3453] Save original picture to photo library

[CB-3453] Save original picture to photo library

- saves original picture when the following camera options are set for no edits (i.e. allowEdit is false, correctOrientation is false, targetWidth/targetHeight are not specified)
- this mirrors cordova-android behavior
- testing done with mobile-spec auto and manual tests


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/5f98661e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/5f98661e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/5f98661e

Branch: refs/heads/master
Commit: 5f98661e0d90a26494b1bb7d82d9ce117facc9dd
Parents: 73f9af5
Author: James Jong <wj...@gmail.com>
Authored: Thu Aug 8 15:01:59 2013 -0400
Committer: Steven Gill <st...@gmail.com>
Committed: Wed Aug 14 13:10:24 2013 -0700

----------------------------------------------------------------------
 src/ios/CDVCamera.m | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/5f98661e/src/ios/CDVCamera.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m
index 11662ed..ebef288 100644
--- a/src/ios/CDVCamera.m
+++ b/src/ios/CDVCamera.m
@@ -303,11 +303,16 @@ static NSSet* org_apache_cordova_validArrowDirections;
             }
 
             NSData* data = nil;
+            // returnedImage is the image that is returned to caller and (optionally) saved to photo album
+            UIImage* returnedImage = (scaledImage == nil ? image : scaledImage);
 
             if (cameraPicker.encodingType == EncodingTypePNG) {
-                data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
+                data = UIImagePNGRepresentation(returnedImage);
+            } else if ((cameraPicker.allowsEditing==false) && (cameraPicker.targetSize.width <= 0) && (cameraPicker.targetSize.height <= 0) && (cameraPicker.correctOrientation==false)){
+                // use image unedited as requested , don't resize
+                data = UIImageJPEGRepresentation(returnedImage, 1.0);
             } else {
-                data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
+                data = UIImageJPEGRepresentation(returnedImage, cameraPicker.quality / 100.0f);
 
                 NSDictionary *controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
                 if (controllerMetadata) {
@@ -323,7 +328,8 @@ static NSSet* org_apache_cordova_validArrowDirections;
             }
             
             if (cameraPicker.saveToPhotoAlbum) {
-                UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
+                ALAssetsLibrary *library = [ALAssetsLibrary new];
+                [library writeImageToSavedPhotosAlbum:returnedImage.CGImage orientation:(ALAssetOrientation)(returnedImage.imageOrientation) completionBlock:nil];
             }
 
             if (cameraPicker.returnType == DestinationTypeFileUri) {