After reading the documentation and sample code from apple regarding the UIImagePickerController and after the read of many tutorials and even Questions here at Stackoverflow (or here), i came to the conclusion, that the builtin UIImagePicker is able to present a "crop window" to the User and let the user crop and move the right part of the Image he wants to use.
But checking out these examples on iOS 7.1, there appears no cropping window. There appears nothing what let the user crop out a part of the taken image. All tests occured on real hardware (iPhone 5S), no iPhone simulator was used here because of missing camera ;)
Also, at the delegate method "didFinishPickingMediaWithInfo" there is no entry of "UIImagePickerControllerEditedImage" in the "info"-NSDictionary.
What i did:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
// iPhone-Simulator has no camera, just save images to the photoalbum on the simulator to use them here
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
[self presentModalViewController:imagePickerController animated:YES];
and the delegate method:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// .... do something
}
At this point, only 3 Keys are available in the Dictionary with the name "info":
nothing else. Also, no cropping window or any similar controls appeared.
Am i wrong with my expectation about the behaviour of the ImagePicker? At this SF-Question the user wrote "Crop window comes up". Was the feature removed? Is the documentation outdated or am i completely wrong here?
I also tried this code taken from another answer to a similar question:
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:^{
// Edited image works great (if you allowed editing)
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}];
}
No cropping window appears, the key "UIImagePickerControllerEditedImage" is not present at the info-NSDictionary.
Can someone explain me the right behaviour? Thank you very much in advance.
this one is works for me:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage, *editedImage;
editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
if (editedImage)
self.profilePictureImageView.image = editedImage;
else
self.profilePictureImageView.image = originalImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With