Question

I'm struggling to get the full resolution when I grab a photo using the AVFoundation. It works fine with the code below but the image is 1080x1920. Yet I know the iPhone5 camera I'm using is 2448x3264.

Setting the stillImageOutput with this:

AVCaptureDevice *videoDevice = 
 [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
videoIn = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];
[session canAddInput:videoIn];
[session addInput:videoIn];

stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
if ([session canAddOutput:stillImageOutput]) {
    [stillImageOutput setOutputSettings:@{AVVideoCodecKey : AVVideoCodecJPEG}];
    [session addOutput:stillImageOutput];
}

Then getting it with:

// Sort orientation
[[stillImageOutput connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[previewLayer.connection videoOrientation]];

// Set the flash to auto
[self setFlashMode:AVCaptureFlashModeAuto forDevice:[videoIn device]];

// Capture a still image.
[stillImageOutput captureStillImageAsynchronouslyFromConnection:[stillImageOutput connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

    if (imageDataSampleBuffer)
    {
        NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
        UIImage *image = [[UIImage alloc] initWithData:imageData];

        NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ImageTaken.jpg"];
        NSData *imageToWriteData = UIImageJPEGRepresentation(image, 0.9f);
        [imageToWriteData writeToFile:jpgPath atomically:YES];
    }
}];

I have a Preview and when the user takes the picture I want it to be what they are previewing but when I do that in the code above it gives me the lower resolution. I understand that the video is done in a lower resolution but how do I get the AVFoundation to use the camera part not just take a frame from the video?

Mike

Was it helpful?

Solution

Try to use this:

session.sessionPreset = AVCaptureSessionPresetPhoto;

or

session.sessionPreset = AVCaptureSessionPresetHigh;

OTHER TIPS

Alas, AVCaptureStillImageOutput is deprecated. I am using:

defaultStillPhotoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top