当我使用AVFoundation拍摄照片时,我很难获得全分辨率。它适用于下面的代码,但图像是1080x1920。但我知道我正在使用的iPhone5相机是2448x3264。
使用以下方法设置stillImageOutput:
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];
}
然后得到它:
// 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];
}
}];
我有一个预览版,当用户拍摄照片时,我希望它是他们正在预览的内容,但是当我在上面的代码中执行此操作时,它会给我较低的分辨率。我知道视频是以较低的分辨率完成的,但如何让AVFoundation使用相机部分而不只是从视频中取出一帧呢?
麦克
答案 0 :(得分:3)
尝试使用它:
session.sessionPreset = AVCaptureSessionPresetPhoto;
或
session.sessionPreset = AVCaptureSessionPresetHigh;
答案 1 :(得分:0)
唉,不推荐使用AVCaptureStillImageOutput。我正在使用:
defaultStillPhotoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:@ {AVVideoCodecKey:AVVideoCodecJPEG}];