How to remove square ratio cropping for images on IOS - ios

I am using the IOS standard image cropping functionality (move and scale) to crop my image before submitting it to the server.
However, I realize that the cropping provided has a square ratio (see screenshot below)
Snippet of the code is as follows:
//set up image picker
self.imgPicker = [[[UIImagePickerController alloc] init]autorelease];
self.imgPicker.allowsEditing = YES;
self.imgPicker.delegate = self;
//Trigger get photo from library function
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imgPicker animated:YES];
How can allow 'move and scale' editing and at the same time allow the user to do cropping WITHOUT the square ratio restriction?

I think you need change self.imgPicker.allowsEditing = YES; to self.imgPicker.allowsEditing = NO;

This library can help you.
https://github.com/gekitz/GKImagePicker
It supports custom cropping and it's easy to integrate with the native picker if needed.

I think , this will serve your purpose . You can change the constraints as you want
https://github.com/kishikawakatsumi/PEPhotoCropEditor?source=cc

Related

Circular crop image while picking it from gallery using ImagePickerViewController

UIImagePickerController* libraryUI = [[UIImagePickerController alloc] init];
libraryUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryUI.delegate = self;
libraryUI.allowsEditing = YES;
[self presentViewController:libraryUI animated:YES completion:nil];
I am using this code to open image picker view and pick an image from gallery. I also set the property "allowsEditing" to "YES" in order to enable the crop image functionality. Now the main issue is that the picker view opened with rectangular crop option. What I want is to get circular crop image option and also want to set the crop circle size (increase or decrease crop circle size).
Since it is not available by default, I will suggest you to use this library:
TOCropViewController
It comes with some other features other than circular crop as well. Objective-C and Swift versions are both available

I used a custom view to preview my UIImagePicker preview, how can I extract the same region from the resulting image as was previewed?

In my view I have a UIView that I use to preview the camera. It's a lot smaller than the regular preview view (128x128). I initialise the UIImagePickerController like this:
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.picker.showsCameraControls = NO;
self.picker.view.frame = self.profilePictureView.frame;
I then use [v addSubview:self.picker.view]; to show the camera's preview within my custom UIVIew. So far this works as intended, I see the part of the camera preview that overlaps my custom view in that view (essentially masking the preview with my custom view).
Now I'm trying to get what is displayed in my UIView into a UIImage (resulting in a 128x128 image). I tried using the delegation methods, but I only get the full size image from the camera there. I also tried taking a screenshot from the view but I got lost...
How can I create a UIImage with the exact same content as the view I use to render the camera preview, including size, offset and ratio?

Objective-C Camera Crop Size

I have a routine that I use to trigger the camera to take a photo. After the camera takes the photo the user is then given an option to crop the image by default before the delegate passes me back the UIImage. Is there any way that I can pass in a dynamic CGRect to make this default crop area a specific size? One thing I should mention is that the application is a landscape iPad application.
Here is a code sample:
-(void)triggerCamera:(id)sender
{
UIImagePickerController *camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.allowsEditing = YES;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
//pass in some sort of CGRect ??
[self presentViewController:camera animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
UIImage *img = [info objectForKey: UIImagePickerControllerOriginalImage];
//process my image further
}
Unfortunately you can't set crop size. I was dealing with same problem over 2 years ago and I got stuck with creating my own viewController for cropping image.
Maybe take a look at GKImagePicker on GitHub. This project hasn't had much activity in the past few months (maybe more), but could be worth a shot. It even comes with an option to have a resizable crop area. I have not tried it myself, but the implementation looks to be pretty simple:
self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 90);
self.imagePicker.delegate = self;
[self presentModalViewController:self.imagePicker.imagePickerController animated:YES];

UINavigation Bar changing tint after using UIImagePickerController

I have a app that can attach a photo to an NSAttributedString in a textView. The UI design has a blue-grey navigation bar with white text.
However, after I use the UIImagePicker, the tint of the NavigationController changes to black text.
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
_imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
_imagePickerController.sourceType = sourceType;
_imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
_imagePickerController.showsCameraControls = YES;
}
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
I'd post an image of the view before launching the UIImagePicker but I don't have enough reputation points (and I don't really know how to get them either).
And I'd post the image after launching the image picker and picking one and returning from the UIImagePicker, but again, not enough reputation points.
Anyone have any ideas if this is 'normal' or a bug ion iOS? Any suggestions on a workaround?
P.S. If you want to see the images, I can email them to you. Any advice is appreciated.
This indeed seems to be a bug, and has been present since iOS 7 beta 6 (or earlier).
There is another SO post about this with some solutions: UIImagePickerController breaks status bar appearance
This problem can be avoided by changing picker's modal presentation class to be different than full screen (e.g. UIModalPresentationPageSheet)
Code:
imagePickerController.modalPresentationStyle = UIModalPresentationPageSheet;

Setting Move and Scale Box for iOS

I have seen several apps that after you take a picture, it shows a view for Move and Scale your picture, with a box showing what the resulting image will look like. My app takes a picture the user takes or picks from library, and adds it to a PDF file. I need this file to be a certain size to fit on the PDF, so I need to set the move and scale box accordingly, but I cannot find any documentation on how to do this. Any suggestions?
Just set the UIImagePickerController instance's allowsEditing to YES.
_imagePickerController = [[UIImagePickerController alloc] init];
...
_imagePickerController.delegate = self;
_imagePickerController.allowsEditing = YES;
The UIImagePickerController picker ONLY performs 320x320 cropping.
Try using this: https://github.com/gekitz/GKImagePicker (GKImagePicker)
Sample Code:
self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 90);
self.imagePicker.delegate = self;
[self presentModalViewController:self.imagePicker.imagePickerController animated:YES];

Resources