How to overlay camera capture image? - ios

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!

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 select Multiple Images from Photo Library?

- (void)pickImage {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
_image = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];
[_imageView setImage:_image];
[self.view addSubview:_imageView];
[self dismissViewControllerAnimated:YES completion:^{}];
}
You can't select multiple photos or videos simultaneously
You have to use custom ImagePicker. And I think ELCImagePickerController is the best option in my opinion.
There is also some other library that can be used..
ELCImagePickerController
WSAssetPickerController
QBImagePickerController
ZCImagePickerController
CTAssetsPickerController
AGImagePickerController

UIImageView rejects `image` after user chooses it from their library - iOS

I've got some basic code to let the user pick an image and set it to an already created UIImageView:
- (void)addAvatarImageView {
self.avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 83, 83)];
self.avatarImageView.imageURL = [[NSURL alloc] initWithString:self.user[#"avatar"]];
[self.avatarView addSubview:self.avatarImageView];
}
and the picker creation:
- (void)showAvatarPicker {
UIImagePickerController *imagePickController = [[UIImagePickerController alloc] init];
imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickController.delegate = self;
imagePickController.allowsEditing = YES;
[self.navigationController presentViewController:imagePickController animated:YES completion:nil];
}
and the picker delegate:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
[self.avatarImageView setImage:image];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
I can breakpoint inside the delegate method and it goes in there fine, but the UIImageView does not show the new image at all. I can't even remove the image that is present either. Any ideas?
I am going to go on a limb here and say that the error is in the portion of the code that you are not showing: where you instantiate your picker. More presicely, you may not have set allowsEditing to yes. So take a look below
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
Alternatively you can just read the original image using UIImagePickerControllerOriginalImage instead of your current UIImagePickerControllerEditedImage.
change UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; to UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];

UIImageViewController has no status after taking photo in preview

I use following code to take picture
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = sourceType;
self.imagePickerController.allowsEditing = YES;
self.imagePickerController.showsCameraControls = YES;
self.imagePickerController.wantsFullScreenLayout = YES;
[self presentViewController:self.imagePickerController animated:NO completion:nil];
after taking, it will jump to a preview with two button: retake and use
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
the above class method can't be called until i click the button use, so is there any class method can I use when entering preview view? thanks

UIIMagePickerController dismissViewControllerAnimated:completion: not working

I'm trying to pick an image from UIImagePickerController and then set it inline inside UITextView. The code below is pretty straightforward. When i tap "act" button, it opens up UIImagePickerController and once it's done, the delegate method didFinishPickingMediaWithInfo gets triggered.
- (IBAction)act:(id)sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
if(!self.imageView){
self.imageView = [[UIImageView alloc] initWithImage:chosenImage];
[self.imageView setContentMode:UIViewContentModeScaleAspectFit];
[self.imageView setFrame:CGRectMake(10.0, 10.0, 100.0f, 100.0f)];
[self.content addSubview:self.imageView];
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:CGRectMake(0.0,0.0,120.0f,110.0f)];
self.content.textContainer.exclusionPaths = #[exclusionPath];
} else {
[self.imageView setImage:chosenImage];
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
Here's the problem: when i try to dismiss UIImagePickerViewController using dismissViewController, it is just ignored. However, it works fine without the two lines where i'm setting the exclusionPaths. Also, this only happens when there's already text in the UITextView. If there's no text, I can do this as many times as I want and dismissViewController works fine. I've stepped through the code and the code actually does pass through the [picker dismissViewControllerAnimated: completion: line. Also picker at that point is indeed an instance of UIImagePickerController. Anyone have idea what is going on?
[UPDATE] I've actually trimmed down the code to the following:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIBezierPath *exclusionPath = [UIBezierPath bezierPathWithRect:CGRectMake(0.0,0.0,120.0f,110.0f)];
self.content.textContainer.exclusionPaths = #[exclusionPath];
[picker dismissViewControllerAnimated:YES completion:nil];
}
Basically I don't even set the imageView anymore. It's just that when I try to set the exclusionPaths of a UITextView--self.content--the dismissViewControllerAnimated:completion: doesn't work. There is no error in the console.
You have to call dismissViewConroller: on self and not picker.
Better yet, call it on picker.presentingViewController like this:
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];

Resources