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];
Related
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?
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];
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 trying to add some basic functionality to a camera application.
The app works like this: You press the camera button somewhere in the app, the camera activates and then gives you some extra basic functionality aside from the flash, switchcameras, cancel and take picture buttons.
Having clicked through quite a bit of search results it seems like only a new cameraoverlay is possible.
Now, I've managed to show some text or a button on itsself somewhere on the camera screen following the scanning example on musicalgeometry.com.
But what I'm trying to do here is add an entire view, constructed in IB, as a cameraOverlay. (for example just a toolbar with some buttons and the rest is blank).
Can I use storyboards for this or is this easier working with Nib files?
Or can the toolbar be programmatically added to a UIView so it can serve as cameraOverlay?
I would think the latter (programmatically) is the most straight forward but I haven't been able to find any examples for either possible solution so anything is welcome.
This is the basic overlay code from the example:
- (void) viewDidAppear:(BOOL)animated {
OverlayView *overlay =
[[OverlayView alloc] initWithFrame:CGRectMake(
0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
// Create a new image picker instance:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
// Set the image picker source:
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Hide the controls:
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
// Make camera view full screen:
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform,
CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
// Insert the overlay:
picker.cameraOverlayView = overlay;
// Show the picker:
[self presentModalViewController:picker animated:YES];
[picker release];
[super viewDidAppear:YES];
}
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