[英]How to get the width and height of the iphone camera
Is there a way to retrieve what width and height the iphone camera is sampling at? 有没有办法检索iPhone相机采样的宽度和高度? I am targetting iOS4 and don't know what the width or height are until I get into the didOutputSampleBuffer delegate.
我的目标是iOS4,直到我进入didOutputSampleBuffer委托之前,我不知道宽度或高度是多少。
Here is the code that actually gets the width and height in the delegate: 这是实际上获得委托中宽度和高度的代码:
- (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);
...
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... 唯一的缺点是,这会在回调中添加nil检查...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.