UIImagePickerController Cropping? - ios

I have read that it is automatic but it doesn't appear to be happening in my case. Using UIImagePickerController with allowsEditing set to YES I get my editing view with the crop square overlay, but when i am finished with the image its not cropped as I expect.
Should it be automatic at this stage? If not, what might be a good solution to crop the image in the matching area that the default view provides?
Thanks.

You are probably using the wrong key for the info dictionary: UIImagePickerControllerOriginalImage.
To get the cropped (yes, it is automatic) image you have to use UIImagePickerControllerEditedImage key.
This should do the trick:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImageEdited = [info objectForKey:UIImagePickerControllerEditedImage];
//dismiss the picker and process the image...
}

Related

iPad image is getting cropped/resized while using image picker controller in objective c

When I use image picker to take photos using iPad camera , the photos are automatically getting resized/cropped while storing it.The same code is working fine with iPhone.Can anyone please help me to find out a solution for this. I am getting this in iOS 9.x.I need original images to be displayed.
Thank you very much in advance.
My issue got resolved when I changed
UIImage * image = info[UIImagePickerControllerEditedImage];
to
UIImage * image = info[UIImagePickerControllerOriginalImage];
in didFinishPickingMediaWithInfo method.

How to get gif asset UIImage

How to load animated GIF image as UIImage from *.imageset folder with different resolutions, without any additional pods?
If i put my GIF images in *.imageset folder they correctly display in XCode http://take.ms/7fsCp, but when i try to load it with UIImage, it returns nil
UIImage *image = [UIImage imageNamed: #"help_image"];
How to make it works?
You can use SDWebImage to do that.
#import "UIImage+GIF.h"
self.imageViewGif.image= [UIImage sd_animatedGIFNamed:#"help_image"];
I hope this can help you.
Add animated Gif image in Iphone UIImageView
check this link you will get your answer Using UIImage category you can get the exect output.

imagePickerController didFinishPickingMediaWithInfo giving me a weird image

I wrote some code to add a photo taken with the camera and add it to a NSMutableArray of UIImages.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.description.text = [NSString stringWithFormat:#"image is %d by %d", image.size.width, image.size.height];
//[self.imageArr addObject:image]
//[self saveImages];
}
The "self.description.text" is a UILabel that I just use to get information when I test on my iPhone (my macbook is too old to upgrade to the last OS and version of Xcode).
I found that when I add the image to my imageArr, the app crashes (I know that imageArr is not nil, I've used the description UILabel to check).
If I comment out the addObject and saveImages functions, I found that, after I take a photo, the description states that the UIImage has a width of 0 and height of 1084850176. Has anyone had this problem before? I've been trying to take and save photos within the app for a few days now, and I can't seem to solve this problem.
EDIT:
I fixed the image dimensions problem by using %f instead of %d (thanks idz!).
It's still crashing when I uncomment the [self.imageArr addObject:image] line. The crash report says the exception type is EXC_CRASH (SIGABRT) when running that line. I don't really know what this means, but I'm sure that imageArr is not nil and it is an NSMutableArray, so I don't see why it keeps crashing there.
Usually you have to allocate and initialize self.imageArr.
That's what usually causes those errors. Also if it's an array make sure it's a mutable array.

Wrong version of image from UIImagePickerController

I have a problem with the UIImagePickerController component. Currently in my app the user can pick an image from the saved photos library with the picker, no problems there.
However, it seems that if I crop and save a photo in Photos.app before picking the image, UIImagePickerController gives me the original uncropped version in the UIImagePickerControllerOriginalImage dictionary key.
I understand that UIImagePickerControllerEditedImage works when the crop is done inside the picker, but when done in the Photos app this key returns nil.
So my question is, how do I access the correct version of the image (without rolling my own picker with ALAssetLibrary)?
The solution was simple; I was using UIImagePickerControllerSourceTypeSavedPhotosAlbum instead of UIImagePickerControllerSourceTypePhotoLibrary.
What is your
-(void)imagePickerController:(UIImagePickerController *)pickr didFinishPickingMediaWithInfo;
method like?
Have you tried to do something like
-(void)imagePickerController:(UIImagePickerController *)pickr didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
[myImageView setImage:image];
[pickr dismissModalViewControllerAnimated:YES];
}
(in the example it's UIImagePickerControllerEditedImage, don't know if you set YES to your picker allowEditing)

UIImagePickerController always pics 640x640 image

When I present a UIImagePickerController in my iPhone App, it always comes up with a white square with a frame around it, and the user has can zoom in and out of an image and make it fit within the white square. Whatever they fit in the white square is what is returned to:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info
and it is always 640x640.
Why can't the user select an entire image? Why does this white square even come up?
Built in editing is very limited. Here is what the Apple documentation says:
Editing controls To specify whether the camera interface should offer
the user controls for moving and scaling the captured picture, or for
trimming the captured movie, set the allowsEditing property to YES (to
provide editing controls) or to NO.
When using built-in editing controls, the image picker controller
enforces certain options. For still images, the picker enforces a
square cropping as well as a maximum pixel dimension. For movies, the
picker enforces a maximum movie length and resolution. If you want to
let the user edit full-size media, or specify custom cropping, you
must provide your own editing UI.
Make sure you're not enable editing for the UIImagePickerController.
You just need this:
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[controller presentModalViewController:imagePicker animated:YES];
[imagePicker release];

Resources