ios - 检查相机的 iOS 捕获分辨率

标签 ios iphone ios7 avcapturesession

我在 iOS 7 上使用 OpenGL 将前置摄像头视频捕获渲染到 UIView 在 iPhone 显示屏上(相同的 iphone 5)。我正在使用 AVCaptureSessionPreset640x480 并将其传递给 AVCaptureSession 方法

[captureSession setSessionPreset:AVCaptureSessionPreset640x480];

然而渲染的视频似乎比上面设置的分辨率低, 它似乎是 AVCaptureSessionPreset352x288。事实上,无论我通过什么常数 从这些没有区别,分辨率是相同的

NSString *const AVCaptureSessionPresetPhoto;
NSString *const AVCaptureSessionPresetHigh;
NSString *const AVCaptureSessionPresetMedium;
NSString *const AVCaptureSessionPresetLow;
NSString *const AVCaptureSessionPreset352x288;
NSString *const AVCaptureSessionPreset640x480;
NSString *const AVCaptureSessionPreset1280x720;
NSString *const AVCaptureSessionPreset1920x1080;
NSString *const AVCaptureSessionPresetiFrame960x540;
NSString *const AVCaptureSessionPresetiFrame1280x720;
NSString *const AVCaptureSessionPresetInputPriority;

如何检查相机实际拍摄的分辨率?

谢谢

最佳答案

读取正在捕获的缓冲区的尺寸,如下所示(对于AVCaptureSessionPresetPhoto,您当然需要捕获静止图像,而不是读取视频帧...):

- (void) captureOutput:(AVCaptureOutput *)captureOutput
       didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
              fromConnection:(AVCaptureConnection *)connection
  {
    CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(imageBuffer,0);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    CVPixelBufferUnlockBaseAddress(imageBuffer,0);

    // "width" and "height" now hold your dimensions...

  }

关于ios - 检查相机的 iOS 捕获分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25069027/

相关文章:

ios - 需要在ios中的didselectitematindexpath上摇动collectionviewcell

ios - 如何通过标签定义标签

ios - 我需要 ViewController 容器还是复合 View ?

iphone - 以编程方式增加音量

ios - 制作触摸时上下滑动的UIView列表

ios - 位置管理器 stopMonitoringForRegion 不工作

bluetooth - iBeacon "Far"、 "Near"和 "Immediate"的标称距离是多少

iOS7忽略文本中的空格

ios - undefined symbol : _OBJC_CLASS_$_FBSDKBasicUtility

iphone - 标签标签 0 的奇怪问题?