Get full image from UIImagePickerController - ios

I have a UIImagePickerController and every time i select an image i get the cropped version of the image, i want the full image, how can i do this?
- (void)tapSelectAd:(id)sender
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
picker.allowsEditing = YES;
picker.wantsFullScreenLayout = YES;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
selectedImage.image = image;
}

Try this: You need to set allowsEditing to NO and use UIImagePickerControllerOriginalImage when you pick your image.
- (void)tapSelectAd:(id)sender
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];
picker.allowsEditing = NO;
picker.wantsFullScreenLayout = YES;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
selectedImage.image = image;
}

Related

Issue with image picker allows editing

I have this method for when the user opens their camera roll. I have the allows editing set to YES but when on the editing screen the square crop box only appears on iphone and not iPad. What am I missing?
- (void)useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = #[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = YES;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
[self presentViewController:imagePicker animated:YES completion:nil];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self setModalPresentationStyle:UIModalPresentationFormSheet];
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
});
}
}
}
And delegate method
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:YES completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
theCustomImage = info[UIImagePickerControllerEditedImage];
[self roundedCorners];
[self placeImage:theCustomImage];
customImage = true;
UIImageWriteToSavedPhotosAlbum(theCustomImage, self, #selector(image:finishedSavingWithError:contextInfo:), nil);
}
}

Camera show black screen in ios 8

This code for capturing image one by one from camera,but after taking one image next time camera will open but with black screen(like it,s shutter close).all other ios version its working,but not working in ios 8.please tell me how can i solve it?
-(void)openCamera
{
if(![PickerHandler doesDeviceSupportMediaType:ITEM_TYPE_PHOTO])
{
[PickerHandler showNoDeviceSupportWarningForMediaType:ITEM_TYPE_PHOTO withDelegate:self];
}
else
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
[self presentViewController:picker animated:YES completion:nil];
}
}
Go to Settings > Privacy > Pictures ... and check if your app have permission.
In the code, use this to verify camera access.
- (BOOL)authorizedCameraAccess
{
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
return (status == AVAuthorizationStatusAuthorized);
}
this code is not work in simulator.
UIImagePickerController *videoScreen = [[UIImagePickerController alloc] init];
videoScreen.sourceType = UIImagePickerControllerSourceTypeCamera;
videoScreen.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
videoScreen.allowsEditing = NO;
videoScreen.delegate = self;
[self presentViewController:videoScreen animated: YES completion:NO];
Implement This method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:NO completion:NO];
}

UIImagePickerController push viewcontroller bug with allowsEditing

I am trying to push a view controller (for extra editing) from UIImagePickerController after user has selected an image.
It is successfully pushed.
But when that view controller is popped and user return to the editing screen, the editing screen is no longer interactable. Does anyone know what is the problem.
-(void)didTapBtn:(id)sender
{
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.picker.delegate = self;
self.picker.allowsEditing = YES;
[self presentViewController:self.picker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (image == nil) {
image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
if (image == nil) {
return;
}
self.test = [[BTTestViewController alloc] init];
self.test.delegate = self;
[self.picker pushViewController:self.test animated:YES];
}
//Called by BTTestViewController
-(void)didCancel
{
[self.picker popViewControllerAnimated:YES];
}
try this one it work in my application:
UIImagePickerController *imagePicker;//put it in .h file
put it in .m file
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"STEP-BY-STEP-STORY!" message: #"Camera is not available" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
imageData.image =[self resizeImage:imageData.image width:200 height:200];
[picker dismissViewControllerAnimated:YES completion:nil];
iphone_filtersViewController *nav=[[iphone_filtersViewController alloc]initWithNibName:#"iphone_filtersViewController" bundle:nil];
[self.navigationController pushViewController:nav animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// release Picker
[picker dismissViewControllerAnimated:YES completion:nil];
}
// iphone_filtersViewController method
-(IBAction)backButton
{
[self.navigationController popViewControllerAnimated:YES];
}
may be it will help.

How to use the allowsEditing

I just want the user to take a photo in app→crop→save. So I would want to use the allowsEditing property of UIImagePickerControl. However I don't know how i can do it. this is my code until now for camera.
-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:NULL];
}
Use this for pick photo from camera
- (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];
}
use this for pick photo from photo library
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
use following two delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Add this in your ViewDidLoad method, so if your device is not support camera then display this alert message.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
Add both protocols to the AppViewController.h file:
#interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

2 UIButtons to set 2 UIImageViews

I've 2 UIButtons, I want both buttons to pick an image, button1 is setting an image to imageview1 and button2 to imageView2. I now created button1 which picks an image and set imageView1 to that image, but if I'm creating button2, I don't now what I have to do in:
- (IBAction)chooseImage1:(id)sender {
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (IBAction)chooseImage2:(id)sender {
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}
UIImage *image;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *mediaURL;
mediaURL = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
image = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
imageView1.image=image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
Create an index in your .h file. Something like
NSUInteger *selectedImageIndex;
And in your .m file :
- (void)showImagePicker:(UIImagePickerControllerSourceType)source{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = source;
ipc.allowsEditing = YES;
ipc.delegate = self;
[self presentModalViewController:ipc animated:YES];
}
- (IBAction)chooseImage1:(id)sender {
selectedImageIndex = 1;
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (IBAction)chooseImage2:(id)sender {
selectedImageIndex = 2;
[self showImagePicker:UIImagePickerControllerSourceTypePhotoLibrary];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = [info objectForKey:#"UIImagePickerControllerEditedImage"];
if (!img)
img = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
if (selectedImageIndex == 1)
imageView1.image=img;
else
imageView2.image = img;
[picker dismissViewControllerAnimated:YES completion:nil];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
But then again, this is just one way to do it.

Resources