iPad take a shot with UIImagePickerController - ios

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.

Related

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];

UIPopoverController content appears too big

Im trying to present a UIViewController that contains a UIWebView inside a UIPopOverController.
The problem is, that the ViewController inside the popOverController "acts" as if it has an entire screen size so i get scroll indicators and scrolling instead of it just "surrendering" to the container size.
Any suggestions?
NSMutableArray *filesArr = AppDelegate.appContentManager.filesArray;
BIDContent *cellContent = ((BIDContent *)[filesArr objectAtIndex:indexPath.row]);
BIDPreviewPopupViewController *popUpContent = [self.storyboard instantiateViewControllerWithIdentifier:#"previewPopup"];
popUpContent.pageContent = cellContent;
_popOverDisplay = [[UIPopoverController alloc] initWithContentViewController:popUpContent];
[_popOverDisplay setPopoverContentSize:CGSizeMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0)];
popUpContent.view.frame = CGRectMake(0, 0, _popOverDisplay.popoverContentSize.width, _popOverDisplay.popoverContentSize.height);
[_popOverDisplay presentPopoverFromRect:[tableView cellForRowAtIndexPath:indexPath].frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:TRUE];
Forgot about a "hidden" gem in the UIWebView - "scales page to fit". Once I turned this on, all was good!

How to set width and positon ModalDialog in the center before it loads?

I created a modal dialog in my viewController.
dialogViewController *dialog = [[dialogViewController alloc] init];
dialog.modalPresentationStyle = UIModalPresentationFormSheet;
dialog.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
dialog.indexPath = indexPath;
dialog.campaignArray = self.campaignArray;
dialog.view.superview.frame = CGRectMake(dialog.view.superview.frame.origin.x+250, dialog.view.superview.frame.origin.y, dialog.view.superview.frame.size.width-250, dialog.view.superview.frame.size.height);
[self presentViewController:dialog animated:YES completion:nil];
The above changes the width but not the x position of the modal dialog. It works in the modalDialog but then user can see it being resized.
If you want to use
UIModalPresentationFormSheet
the controller will be centred. There is very specific formatting included in this. If you want anything different, you will have to build your own.
The width and height of the presented view are smaller than those of the screen and the view is centered onscreen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
Try this:
dialogViewController *dialog = [[dialogViewController alloc] init];
dialog.modalPresentationStyle = UIModalPresentationFormSheet;
dialog.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
dialog.indexPath = indexPath;
dialog.campaignArray = self.campaignArray;
[self presentViewController:dialog animated:YES completion:nil];
CGRect dlgFrame = dialog.view.superview.frame;
dlgFrame.size.width -= 250.0;
dialog.view.superview.frame = dlgFrame;

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