Save photo on use button click in camera app - ios

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

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.

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.

Setting Image picker sourceType so that only pictures and no video can be selected

I want users to be able to use a camera but not have the option of taking a video. As it stands, both photo and video controls show in the bottom left corner of the view when camera is launched by user. Below are my launchCamera and imagePickerController methods.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
self.challengePic.image = self.image;
if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
self.challengePic.image = self.image;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)launchCamera:(id)sender {
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
- (IBAction)launchAlbum:(id)sender {
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
}
Is there any way of setting the Image picker sourceType so that only pictures and no video can be selected? Thanks in advance!
Don't include this line:
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
From the UIImagePickerController class Reference:
By default, this property is set to the single value kUTTypeImage,
which designates the still camera interface when capturing media, and
specifies that only still images should be displayed in the media
picker when browsing saved media. To designate the movie capture
interface, or to indicate that only movies should be displayed when
browsing saved media, use the kUTTypeMovie identifier….
If you only want to select images, don't set the mediaTypes property to all possible media types for the given source.
By default, the image picker will only show images from the photo library.
But your setting of mediaTypes is overriding this default and allowing videos as well.
If you only want to select images or videos, you can use a code like this.
self.imagePicker.mediaTypes = ["public.image"]
or
self.imagePicker.mediaTypes = ["public. movie"]

ioS7: Capture multiple images from camera and store in array

guys.
I'm trying to capture multiple images from the camera in iOS7, when I capture the first image and click in in "Use Photo", then it's store the image in a array in didFinishPickingMediaWithInfo. When the camera appear again, I see the last image in background but I can't see the camera movement. I know the camera is enabled, because it's searching faces. The code is below:
- (IBAction)openTour:(id)sender
{
_counter=0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker = nil;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage];
[ _imageArray addObject:image ];
_counter++;
if ( _counter<5 )
{
[self dismissViewControllerAnimated:NO completion:nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:nil];
imagePicker = nil;
}
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Does anyone know what is happening?
Thanks in advance!
Set showsCameraControls = NO;
Use cameraOverlayView property.
In the action of your camera button call takePicture method.
Keep adding UIImage objects received by the method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

Using GKImagePicker to crop photo

I want to crop a photo that is taken in the app and then save. I am using the GKImagePicker so that I can do this but if I use the code below even though I push the take photo button in my app it shows me the photo library which I pick to crop. I do not want to do this and just want to crop my photo which I have taken in the app.
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 320);
self.imagePicker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:self.imagePicker.imagePickerController animated:YES];
[self presentViewController:picker animated:YES completion:NULL];
}
Remove the last line in your code:
[self presentViewController:picker animated:YES completion:NULL];// remove
and give it a try ;)
You can also check this.

Resources