Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom UIImagePickerController with full-screen images ios

I have a simple UIImagePickerController which will use the camera to take a picture, but there are a couple things I would like it to do:

  • Have a custom camera UI
  • Take a full-screen instead of 480x640 (if on 4inch phone)

Here is my code for showing the UIImagePickerController:

- (IBAction)pick:(id)sender {
    NSLog(@"abc");
    picker = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
    } else {
        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
    [picker setDelegate:self];
    [self presentViewController:picker animated:YES completion:nil];

}

and here is for when the image gets taken:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];
}

How do I do this?

Thanks

like image 919
Jason Silberman Avatar asked Apr 07 '13 17:04

Jason Silberman


People also ask

What is Iphone photo picker?

The system Photos picker is the best way for most apps to access photos and videos on iOS. The picker runs out of process, so your app doesn't need to request any library access to use it. It has an intuitive UI and an easy-to-use API.

What is kUTTypeImage?

kUTTypeImage is actually default for the mediaTypes property. It states, that one can only pick still images. If you are ok with this default, you don't need to set it explicitly in your code.

What is image picker?

expo-image-picker provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera.


1 Answers

For the first bullet point I suppose that you could use the cameraOverlayView property of an UIImagePickerController object to add your custom UI over the picker default interface:

- (IBAction)pick:(id)sender {
    NSLog(@"abc");
    picker = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
    } else {
        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }

    // Add here your custom UI here
    [picker setCameraOverlayView:self.customCameraOverlayView];

    [picker setDelegate:self];
    [self presentViewController:picker animated:YES completion:nil];

}

EDIT

I've tested the UIImagePickerController and it returns the image with it's full dimensions (PixelXDimension and PixelYDimension):

 UIImagePickerControllerMediaMetadata =     {
        DPIHeight = 72;
        DPIWidth = 72;
        Orientation = 6;
        "{Exif}" =         {
            ApertureValue = "2.526068811667588";
            BrightnessValue = "-0.5779073354035674";
            ColorSpace = 1;
            DateTimeDigitized = "2013:04:07 22:30:03";
            DateTimeOriginal = "2013:04:07 22:30:03";
            ExposureMode = 0;
            ExposureProgram = 2;
            ExposureTime = "0.05882352941176471";
            FNumber = "2.4";
            Flash = 24;
            FocalLenIn35mmFilm = 35;
            FocalLength = "4.28";
            ISOSpeedRatings =             (
                800
            );
            MeteringMode = 3;
            PixelXDimension = 3264;
            PixelYDimension = 2448;
            SceneType = 1;
            SensingMethod = 2;
            ShutterSpeedValue = "4.058893689053568";
            SubjectArea =             (
                1874,
                1478,
                610,
                612
            );
            WhiteBalance = 0;
        };
        "{TIFF}" =         {
            DateTime = "2013:04:07 22:30:03";
            Make = Apple;
            Model = "iPhone 4S";
            Software = "6.1.3";
            XResolution = 72;
            YResolution = 72;
        };
    };

EDIT

Also you could set to your image view the content mode to resize and fit the container view:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setContentMode:UIViewContentModeScaleAspectFill];
    [imageView setImage:image];
}

and after that to fit the imageView as you need in you view controller taking in consideration the device screen (4inch or not) using auto layout or auto sizing.

like image 113
alexcristea Avatar answered Sep 30 '22 18:09

alexcristea