有没有办法检索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);
...
答案 0 :(得分:0)
我的解决方案是延迟构建我需要知道宽度和高度的对象,直到我进入委托回调。然后我就用
if (myObject != nil)
{
// create with width and height
}
唯一的缺点是这会给回调添加一个零检查......