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...
精彩评论