Where does my picture go? - ios

I'm creating an app that allows the user to take a picture. I'm using the code bit below and then load the image into an UIImageVIew to display on screen. No problems, but once I've taken the image, where does it go? If I don't actually save the image to my camera roll, where is it? Is it held in memory until I close my app?
Can I save is somehow with NSUserDefaults?
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
[self presentViewController:picker animated:YES completion:NULL];
}

using something like this UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; self.myImage = chosenImage; will store your image in your app and you can call on it again later

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.

full screen camera in ios

I'm using the following code so the user can take a pic:
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
Is there a way to make the camera occupy the hole screen?
What you're seeing is the default implementation of UIImagePickerController which includes camera controls.
Try turning these off by setting showsCameraControls to NO.
If you want to add your own controls, use cameraOverlayView.

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.

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