开发者

How to get the width and height of the iphone camera

开发者 https://www.devze.com 2023-01-07 23:44 出处:网络
Is there a way to retrieve what width and height the iphone camera is sampling at? I am targetting iOS4 and don\'t know what the width or height are until I get into the didOutputSampleBuffer delegate

Is there a way to retrieve what width and height the iphone camera is sampling at? I am targetting iOS4 and don't know what the width or height are until I get into the didOutputSampleBuffer delegate.

Here is the code that actually gets the width and height in the delegate:

    - (void) captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampl开发者_开发百科eBuffer 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);

...


My solution was to delay construction of my object that needed to know the width and height until I get into the delegate callback. Then I just use

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

The only downside is that this adds a nil check to the callback...

0

精彩评论

暂无评论...
验证码 换一张
取 消