【问题标题】:Not getting full resolution from AVFoundation camera无法从 AVFoundation 相机获得全分辨率
【发布时间】: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


    【解决方案1】:

    尝试使用这个:

    session.sessionPreset = AVCaptureSessionPresetPhoto;
    

    session.sessionPreset = AVCaptureSessionPresetHigh;
    

    【讨论】:

    • 只有 AVCaptureSessionPresetPhoto 提供相机支持的最高分辨率。
    • stillImageOutput 设置为将highResolutionStillImageOutputEnabled 设置为true 也很重要。
    【解决方案2】:

    唉,AVCaptureStillImageOutput 已被弃用。我正在使用:

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

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多