Edit image after shooting

I am currently making an iphone application where a user takes a photo or selects it from an album, and then an inscription is placed on top of the image. Then the user can scale, rotate and save the image. Currently, I can take pictures or choose one for the album. As for the overlay, I just used UIImageView and placed it on top of the hierarchy in the interface builder. For the camera, I use this code:

-(IBAction)getPhoto:(id)sender { // Create an image picker controller UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init]; if((UIButton *) sender == choosePhotoBtn) { // Set source to photo albums imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } else { // Set source to camera imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.showsCameraControls = YES; } // Delegate is self imagePicker.delegate = self; // Allow editing of image imagePicker.allowsEditing = YES; // Show image picker [self presentModalViewController:imagePicker animated: YES]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // Dismiss modalviewcontroller [picker dismissModalViewControllerAnimated:YES]; // Displaying image to the imageView imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; // Access the uncropped image from info dictionary UIImage * image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; // Save Image UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); [picker release]; } 

The problem that I am currently facing is editing the photo after taking it. How to configure the camera in this way:

  • Choose either use the camera or get a photo from an album

  • After selecting the overlay image will change to one where I put a β€œcircle” in the face, and the photo will be masked. This view will also be able to edit in full screen. You can rotate, scale and move the image until you click on it.

I read this part in the manual, but I cannot figure out how to use it. http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Hope someone can point me in the right direction.

Many thanks. -Hakimo

+6
source share
2 answers

there a lot of things will not change your code:

 - (IBAction)takePicture:(id)sender { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; } else { [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; } [imagePicker setAllowsEditing:YES]; [imagePicker setDelegate:self]; //place image picker on the screen [self presentViewController:imagePicker animated:YES completion:nil]; } 

If you want to use an image that is after editing, change "UIImagePickerControllerOriginalImage" to "UIImagePickerControllerEditedImage", what is it!

+19
source

In Q1, is it possible to implement an action sheet so that the user can select a photo or album? with an action sheet function, something like the following:

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { picker = [[UIImagePickerController alloc]init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; [self presentModalViewController:picker animated:YES]; [picker release]; } else if (buttonIndex == 1) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { picker = [[UIImagePickerController alloc]init]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.allowsEditing = YES; picker.delegate = self; [self presentModalViewController:picker animated:YES]; [picker release]; } else { UIAlertView *noCameraMsg = [[UIAlertView alloc] initWithTitle:@"no camera on this phone" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [noCameraMsg show]; [noCameraMsg release]; } } 
0
source

Source: https://habr.com/ru/post/890394/


All Articles