Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

uiimageview - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...