如何获得iPhone相机的宽度和高度

时间:2010-07-18 05:35:20

标签: iphone xcode camera

有没有办法检索iphone相机采样的宽度和高度?我的目标是iOS4,在进入didOutputSampleBuffer委托之前,我不知道宽度或高度是多少。

以下是实际获取委托中宽度和高度的代码:

    - (void) captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection
    {
        CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
        CVPixelBufferLockBaseAddress(imageBuffer, 0);
        uint8_t* baseAddress = (uint8_t*)CVPixelBufferGetBaseAddress(imageBuffer);
        size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
        size_t width = CVPixelBufferGetWidth(imageBuffer);
        size_t height = CVPixelBufferGetHeight(imageBuffer);

...

1 个答案:

答案 0 :(得分:0)

我的解决方案是延迟构建我需要知道宽度和高度的对象,直到我进入委托回调。然后我就用

if (myObject != nil)
{
    // create with width and height
}

唯一的缺点是这会给回调添加一个零检查......

相关问题