Capture and custom crop image with camera iOS - ios

I am using UIImagePickerController to capture the image. Now I want to crop the image. I am using cameraOverlayView method of UIImagePicker but it does not allow to move my cropping view. I want my cropping view should be moveable and resizable so that user can select image portion to use.
I am using the following code:
UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];
cameraPicker.delegate = self;
cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
cameraPicker.cameraOverlayView =overlay;
cameraPicker.allowsEditing = NO;
[self presentViewController:cameraPicker animated:YES completion:nil];
Can anyone suggest what can I do?

- (void)pickphoto:(UIImagePickerControllerSourceType)sourceType
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.navigationBar.tintColor=[UIColor blackColor];
imagePicker.navigationItem.title=#"Photo Albums";
imagePicker.AllowsEditing = TRUE;
imagePicker.delegate = self;
imagePicker.sourceType = sourceType;
[self presentModalViewController:imagePicker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
_imageV.image = image;
_imageV.layer.borderColor=[UIColor whiteColor].CGColor;
_imageV.layer.borderWidth=1.0;
[imagePicker dismissModalViewControllerAnimated:YES];
}

Related

objective c - after picking image from gallery or camera - needs to enable rotate, flip editing

After picking the image from gallery or camera - needs to enable rotate, flip editing How can i acive that.Here my code :
-(void)photofromCamera
{
#try
{
NSLog(#"2");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
#catch (NSException *exception)
{
[self showAlert:#"Camera is not available"];
}
}
-(void)photofromGallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
So after the delegate method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.imageDeletionButton setHidden:NO];
UIImage *chosenImage = [info valueForKey:UIImagePickerControllerEditedImage];
self.PostImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
As if now, if i pick any image from gallery, camera - i needs to show the crop, flip, rotation.please help me out how can i achive that.
Thanks in advance !!!
You can use the swift based framework IGRPhotoTweaks for rotate, flip and crop the image.
You can check the https://github.com/IGRSoft/IGRPhotoTweaks for git and
https://cocoapods.org/pods/IGRPhotoTweaks for cocoapods.
In the framework cropAction() and changedAngel(value: radians) are the 2 methods that you need to try to achieve your requirement.

How to overlay camera capture image?

I am replacing the part of image by capture image from camera. i need to perform the activity like this app in my application. https://itunes.apple.com/in/app/replace-my-face-funny-girls/id794033892?mt=8
I need a way of how can i take picture from background view with super view image and save the new generated image with merging of both image.
Please suggest me solution.
The simple work i did
- (void)viewDidLoad {
[super viewDidLoad];
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.delegate = self;
self.picker.allowsEditing = NO;
self.picker.showsCameraControls = NO;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
CGRect overlayRect = CGRectMake(0, 0, self.imageView.frame.size.width,self.imageView.frame.size.height);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
UIImageView *capture_image=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.imageView.frame.size.width,self.imageView.frame.size.height)];
capture_image.image=[UIImage imageNamed:#"1.jpg"];
[overlayView addSubview:capture_image];
[self.picker setCameraOverlayView:overlayView];
[self.navigationController presentViewController:self.picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Please also suggest me if there is any repository working like this approach.
About capturing the image: you might want to look at FastttCamera, which allows you to set the camera view to your defined image view and crops the image accordingly.
Good luck!

Display photos taken in different image views

I have two image views. When I click a button (e.g. takePhoto) underneath of the 1st image view, the photo taken appears in the first image view. However, when I tap the second "takephotoTwo" button, I want the second photo taken to appear in the second image view (imageTwo). Right now, if I take a photo using the second "takephotoTwo" button, the final (same) image appears in both image views. See code below - does anyone know how I can fix this? I hope I explained this well enough.
E.g.
The photo taken with takePhoto (button) should appear in imageView, and the photo taken with takephotoTwo (button) should appear in imageTwo.
ViewController.m
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *secondImage = info[UIImagePickerControllerEditedImage];
self.imageTwo.image = secondImage;
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
This is easily achieved by keeping track of which button was tapped or storing a reference to the proper image view based on which button was tapped. Then in the image picker delegate method you set the appropriate image view.
Add an instance variable of type UIImageView * named selectedImageView.
Then update the rest of your code as follows:
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
selectedImageView = self.imageView; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
selectedImageView = self.imageView; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
selectedImageView = self.imageTwo; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
selectedImageView = self.imageTwo; // Add this
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = info[UIImagePickerControllerEditedImage];
selectedImageView.image = image;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
The problem is that no matter which button is tapped, you are giving your UIImagePickerController the same delegate. Therefore the same imagePickerController:didFinishPickingMediaWithInfo: is called. But at that point you have no way of knowing which button was tapped, so you have no way of knowing what image view to put the picture into.
Either give the UIImagePickerController a different delegate for each different button, or store in an instance variable somewhere some information about which button was tapped, so that imagePickerController:didFinishPickingMediaWithInfo: can decide correctly what to do.

UIImagePickerController on Subview and Show Photo on UIImageView

I use UIImagePickerController on a subview (280x240). I use this code:
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeAuto];
[imagePicker setShowsCameraControls:NO];
[imagePicker viewWillAppear:YES]; // trickery to make it show
[imagePicker viewDidAppear:YES];
[self.borderView addSubview:imagePicker.view]; //borderView size is 280x240
I am taking image picker original image and I want to take only displayed area on subview (borderView). How can I do?
try this.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker = [[MyImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.showsCameraControls=YES;
[self presentViewController:imagePicker animated:YES completion:^{
NSLog(#"Completed");
}];
and then call delegate method of UIImagePickerController
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
capturedPicImageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[capturedPicImageView sizeToFit];
capturedPicImageView.contentMode = UIViewContentModeScaleAspectFill;
capturedPicImageView.image = [self resizeAndStoreImages:capturedPicImageView.image];
UIImageWriteToSavedPhotosAlbum(capturedPicImageView.image, nil, nil, nil);
}

Save photo on use button click in camera app

My current code is :
- (IBAction)cameraButtonAction:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = NO;
picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
This is bringing up the default camera, but when I select use it does not save the picture. I have tried :
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[self dismissModalViewControllerAnimated:YES];
}
Every tutorial i have looked at, they make a custom camera app using a UIImageView but this is not what I want to do, I do not want to display the image back in the app and want to keep the default camera functions.
Your code is correct. But you didn't set the delegate
You are missing a single line here:
picker.delegate = self;
You need to add that in your cameraButtonAction method.
- (IBAction)cameraButtonAction:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}

Resources