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];
Related
Is there a way to set the camera photo mode fullscreen on an iPod 5gen with iOS7.1? When you are going to take a photo, the photo mode is not in fullscreen, only the video mode is in fullscreen, so, is there a way to change it? (I think the same problem must happen on an iPhone 5 and greater).
Here is my code so far, it displays the control but partially, not fullscreen, and the control gets aligned to the top because the camera controls are removed from the view:
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.allowsEditing = NO;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.showsCameraControls = NO;
//self.picker.mediaTypes = mediaTypes; //just for the record
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.modalPresentationStyle = UIModalPresentationFullScreen;
self.picker.cameraOverlayView = [self buildOverlay]; //some custom views
[self presentViewController:self.picker animated:YES completion:NULL];
Thank you very much in advance.
Apply proper CGAffineTransform transformation in order to set camera mode.
Try out the following link this may help you:
here
About this question:
Device: iPod touch 4th gen (640 * 960 retina display resolution)
OS: iOS 6
Dev Kit: XCode 5.0.2
Source code I try to modify: PhotoPicker example
Aim: add image on top of UIImagePickerController view
Description:
I am modifying the PhotoPicker example from Apple with the aim to add a custom PNG image displayed above the camera lenses before taking the picture. The image will indicate where the user has to put his/her face.
The image below shows what I get and what I want. As you can see it seems that the original image does get rescaled and becomes way too big.
The main method that is called when the "camera" button is tapped is the following. I modified it adding a UIImageView subview to imagePickerController, where I initialized the UIImageView with a UIImage containing the original 640*960 image.
When I run this piece of code on my iPod 4th generation (640 * 960) it seems that the image that is scaled a lot. How can I fix my code below to allow the image to overlay perfectly the camera? (the dot should appear in the center and the black borders in the borders)
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
{
[self.imageView stopAnimating];
}
if (self.capturedImages.count > 0)
{
[self.capturedImages removeAllObjects];
}
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
/*
The user wants to use the camera interface. Set up our custom overlay view for the camera.
*/
imagePickerController.showsCameraControls = NO;
// Set rear camera
imagePickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;
/*
Load the overlay view from the OverlayView nib file. Self is the File's Owner for the nib file, so the overlayView outlet is set to the main view in the nib. Pass that view to the image picker controller to use as its overlay view, and set self's reference to the view to nil.
*/
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
imagePickerController.cameraOverlayView = self.overlayView;
self.overlayView = nil;
UIImage * imageOfFaces = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"photo border" ofType:#"png"]];
UIImageView * imageViewOfFaces = [[UIImageView alloc] initWithImage:imageOfFaces];
[imagePickerController.view addSubview:imageViewOfFaces];
[imageViewOfFaces sizeToFit];
}
self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
Full size images:
Here is the PNG image I would like to overlay (is 640w * 960h pixel):
However this is the result:
Make sure your image has the retina suffix like this:
image#2x.png
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];
I 'm trying to take a shot and it works, but with 2 problems. First, the pop over controller is displayed in a minimum size (it doesn't obey the setPopoverContentSize) and second and most important, the captured shot is only 640x640 pixels, whereas I want to be the maximum available (5MP).
What's the problem in the following code?
imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imgPicker.showsCameraControls = YES;
pop = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
pop.delegate = self;
CGRect re = CGRectMake(50,20,100,20);
CGRect re2 = CGRectMake(0,0,500,500);
[pop setPopoverContentSize:re2.size];
[pop presentPopoverFromRect:re inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Thanks a lot
You are setting the content size incorrectly. You don't call setPopoverContentSize: on the popover, you call it on the view controller that is displayed in the popover. In your case, set the content size of the image picker.
The image received from the image picker is the full sized image. Perhaps you are obtaining the edited image instead of the original image.
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