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.
Related
Thumbnails do not display in the UIImagePickerController when running on iPhone 11 or real device with iOS 14.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:nil];
Result:
Photos and Albums showing as Blank but when I tap on-screen image will be selected.
For me, it was caused by using
UIScrollView.appearance(whenContainedInInstancesOf: [UINavigationController.self]).backgroundColor = .backgroundPrimaryNew
I don't know why is that, but after I've removed this line it began working again and thumbnails are showing.
Try this
Instead of presenting add UIImagePickerController as subView
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self.view addSubview:self.picker.view];
[self addChildViewController:self.picker];
[self.picker didMoveToParentViewController:self];
In iOS10 click camera an option of take photo not manual click that one automatically taken photo so how can create take photo with manual click?
I tried this following code:
- (void)cameraAndPhotogalleryMethod{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.showsCameraControls = YES;
[self presentViewController:picker animated:YES
completion:^ {
[picker takePicture];
}];
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}}
- (void)cameraMethod{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.showsCameraControls = YES;
[self presentViewController:picker animated:YES
completion:^ {
[picker takePicture];
}];}
Add this properties in info.plist file
1.If you Access the camera on ios 10.You should add the code in plist.Try this code.
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use your camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to use your photo library</string>
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.
I created a CameraOverlayViewController with .xib file to implement a customized camera overlayView with. The overlayView is just a transparent background with a button to select photo from the photoLibrary and it loads successfully in the mainViewController with the following code:
CameraOverlayViewController* overlay = [[CameraOverlayViewController alloc] initWithNibName:#"CameraOverlayViewController" bundle:nil];
cameraPicker.cameraOverlayView = overlay.view;
However, nothing happens when I pressed the button on the cameraOverlayView. No error messages, nothing. Does anyone know what's going on here? Below is my code in the CameraOverlayViewController file:
- (IBAction)select:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:picker
animated:YES completion:nil];
}];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
NSLog(#"Just work alrdy!!!");
}
Thanks in advance!
Try This..
-(IBAction)select:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:picker
animated:YES completion:nil]; ////////check this is called??????
}];
}
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