I want to get the image frm imagepickercontroller
.But my code doesn't have any effect
Here is the code..
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
imageview.image = [UIImage imageNamed:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
You can try this code to access an Image returned from the picker
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage* originalImage = nil;
originalImage = [info objectForKey:UIImagePickerControllerEditedImage];
if(originalImage==nil)
{
originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if(originalImage==nil)
{
originalImage = [info objectForKey:UIImagePickerControllerCropRect];
}
//At this point you have the selected image in originalImage
[self saveImageToDocumentDirectory:originalImage];
}
Try
imageview.image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
Updated for Swift 5, the following will safely unwrap the UIImage
.
// This uses the full key value
guard let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { return }
// This uses only the info key value for shorter code
guard let image = info[.originalImage] as? UIImage else { return }
just try this
imageview.image = [info objectForKey:UIImagePickerControllerOriginalImage];