2010-07-18 126 views
1

有没有办法来检索iphone相机取样的宽度和高度?我正在瞄准iOS4,直到进入didOutputSampleBuffer委托,才知道宽度或高度是多少。如何获得iPhone相机的宽度和高度

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

- (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

我的解决办法是推迟建设我的对象,它需要知道的宽度和高度,直到我进入委托回调。然后,我只是用

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

唯一的缺点是,这增加了一个零检查回调...

相关问题