Reputation: 2724
I'm having a bit of a problem that I can't really understand. When I grab an image through UIImagePickerController for most cases I'm returned an UIImage. This line
UIImage* outputImage = [info objectForKey:UIImagePickerControllerEditedImage]? : [info objectForKey:UIImagePickerControllerOriginalImage];
But occasionally, I'm returned a Null image. And I cannot seem to figure out why. Has anyone experience something similar to this?
I seem find it returning these null images more often from images saved from the web. But I cant say that it's exclusively that.
Thanks!
Full method. This happens when the user picks an image from the picker.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* outputImage = [info objectForKey:UIImagePickerControllerEditedImage]? : [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"Output Image : %@", outputImage);
}
and the return i get from the Log is
Output Image : (null)
Upvotes: 2
Views: 1096
Reputation: 1266
Set allow editing to UIImagePickerController
.Like
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.allowsEditing = YES;
Upvotes: 3
Reputation: 780
I know that this is late, but I recently ran into a similar problem with the value being returned is null. If you are not actually editing the image, it would be safe to say to just use : UIImage* outputImage = info[UIImagePickerControllerOriginalImage];
The problem with your code about, which I believe the other guy was trying to say was that ternary operator is in the wrong place. The correct way to use a ternary operator is (condition) ? (if_true) : (if_false)
.
Good luck to anyone if they might be running into a similar problem.
Upvotes: 1
Reputation: 102
Your code is incorrect. construction "?:" should be this: (bool expression)? "choose if YES" : "choose if NO". In your code isn't present "choose if YES". I don't understand while compiler pass this but may be it put "nil" for "choose if YES". I've noted that EditedImage never be nil so You always choose nil. The correct code should be:
UIImage* outputImage = [info objectForKey:UIImagePickerControllerEditedImage] ? [info objectForKey:UIImagePickerControllerEditedImage] : [info objectForKey:UIImagePickerControllerOriginalImage];
but take in mention that i never see
[info objectForKey:UIImagePickerControllerEditedImage] == nil ))))
Sorry for my bad english. Good luck!
Upvotes: 0