【发布时间】:2017-06-19 01:12:36
【问题描述】:
当我使用 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 使用相机部分而不仅仅是从视频中获取一帧?
迈克
【问题讨论】:
标签: ios avfoundation