简体   繁体   English

如何获得iPhone相机的宽度和高度

[英]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.

相关问题 如何知道字符串的宽度和高度知道它在iPhone中的字体大小? - How to get the width and height of a string knowing its font size in iPhone? Javascript iPad,iPhone和Android-如何获取页面的完整宽度和高度? - Javascript iPad, iPhone and Android - How to get page full width and height? 如何使用MonoTouch获得iPhone / iPad的宽度和高度? - How to get width and height of iPhone/iPad using MonoTouch? iPhone XR的摄像头图像在javascript中的宽度和高度已切换 - IPhone XR , image from camera have width and height switched in javascript 任何人都可以解释iPhone 4上从iPhone相机拍摄的图像返回的宽度/高度吗? - Anyone could exlain width/height returned from iphone camera taken image on iPhone 4? iPhone(/ iPad)上的高度和宽度 - Height and width on iPhone (/iPad) 如何在iPhone的UISearchBar中更改UiSearchbar的高度,宽度,颜色和Uitextfield高度? - How to change the UiSearchbar height ,width , color and Uitextfield Height in UISearchBar in iphone? 如何获得物体的高度和宽度? - How to get height and width of the object? 在iPhone中完全加载之前获取图像宽度和高度 - Get image width and height before loading it completely in iPhone 如何在iOS中使用相机计算物体的高度和宽度? - How to calculate height and width of object using camera only in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM