Reputation: 5775
I am using a UIImagePickerController
with the property allowsEditing
set to YES
.
When the user finish picking an image I want to know if the user edited the image he selected or not (e.g. if he scaled the image). This method:
UIImage *editedImage = [info objectForKey:@"UIImagePickerControllerEditedImage"];
returns always an object even if the user left the picture as it was. Is there any way to check if the user edited the image? For example can i check if the UIImagePickerControllerEditedImage
and UIImagePickerControllerOriginalImage
are different somehow?
Upvotes: 2
Views: 2316
Reputation: 21
I know that this is a very old question, with no activity in awhile, but this is what comes up in a google search, and as far as I can tell, the question remains unanswered satisfactorily.
Anyway, the way to tell if the image has been edited or not is this:
In didFinishPickingMediaWithInfo: you can inspect the width of the CropRect and the width of the original image. If CropRect.width == originalImage.width+1, then it has not been edited. The reason this is true is because to edit the image, the user must pinch and zoom, which scales the image and changes the size of the CropRect. Simply moving the image around will not work as it bounces back unless it is scaled.
NSValue *pickerCropRect = info[UIImagePickerControllerCropRect];
CGRect theCropRect = pickerCropRect.CGRectValue;
UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
CGSize originalImageSize = originalImage.size;
if (theCropRect.size.width == originalImageSize.width+1) {
NSLog(@"Image was NOT edited.");
} else {
NSLog(@"Image was edited.");
}
As far as I can tell this works in iOS 9 on the 6S and 6+. I see no real reason it shouldn't work elsewhere.
Upvotes: 0
Reputation: 83
Check this out:
This is the docs for the ImagePicker Delegate. As you can see, when the user picks and image this is called:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
info - is a dictionary which contains data about what happened and what has been picked. if allowediting is set to YES then info contains both the original image and the edited one. Check in the link I gave you for the
Editing Information Keys
there are a bunch of constants there which can give you the data you seek!
Start from here to see the whole mechanics: http://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/instp/UIImagePickerController/allowsEditing
Upvotes: 0
Reputation: 1213
Could you not just get and compare the CGSize of the image?
BOOL sizeChanged = FALSE;
// get current size of image
CGSize originalSize = [image size];
//After the user hase made the action, get the new size
CGSize currentSize = [image size];
// if the dimensions have been editied the condition is true
if ( originalSize.width != currentSize.width ||
originalSize.height != currentSize.height
)
sizeChanged = TRUE;
else
sizeChanged = FALSE;
Upvotes: 0
Reputation: 6427
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *editedimage = [info objectForKey:UIImagePickerControllerEditedImage];
if(editedimage.length>0){
//then got the edited image
}
Upvotes: 0
Reputation: 38249
Try this in didFinishPickingMediaWithInfo as i am not sure:
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *editedimage = [info objectForKey:UIImagePickerControllerEditedImage];
if ([UIImagePNGRepresentation(image) isEqualToData:UIImagePNGRepresentation(editedimage)])
//not edited
else
//edited
Upvotes: 8