[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
This commit is contained in:
James Jong 2013-08-08 15:01:59 -04:00 committed by Steven Gill
parent 73f9af5b84
commit 5f98661e0d

View File

@ -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) {