【问题标题】:How do I create a CVPixelBuffer with 32RGBA format for iPhone?如何为 iPhone 创建 32RGBA 格式的 CVPixelBuffer?
【发布时间】:2011-12-23 04:34:03
【问题描述】:

在尝试创建 32 位 RGBA CVPixelBuffer 时,我经常遇到错误。

最明显的错误 -6680 表示:“缓冲区不支持指定的像素格式。”

这是代码片段:(宽度和高度指定为256*256)

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferCGImageCompatibilityKey,
//                         [NSNumber numberWithBool:YES], kCVPixelBufferOpenGLCompatibilityKey,
                         nil];
CVPixelBufferRef pxbuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, WIDTH,
                                      HEIGHT, kCVPixelFormatType_32RGBA, (CFDictionaryRef) options, 
                                      &pxbuffer);
NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL);

谁能提示我做错了什么?

【问题讨论】:

    标签: iphone opengl-es rendering framebuffer


    【解决方案1】:

    您需要使用不同的像素格式。仅仅因为为 32RGBA 定义了一个常量并不意味着它受支持。本技术说明列出了支持的格式(截至撰写时)以及可用于了解当前支持哪些格式的函数:

    Technical Q&A QA1501 Core Video - Available Pixel Formats

    受支持的最相似格式是 32ARGB 和 32BGRA。

    【讨论】:

    • 这很奇怪。因为我需要新的 CVOpenGLESTextureCacheCreateTextureFromImage 函数的这种缓冲区格式。在 RosyWriter 苹果示例中,他们使用了这种格式(尽管他们从相机中获取了这个缓冲区)。
    • RosyWriter 没有提到kCVPixelFormatType_32RGBA。在对CVOpenGLESTextureCacheCreateTextureFromImage的调用中,它使用GL_RGBA作为internalFormat参数,但它使用GL_BGRA作为format参数,“指定像素数据的格式”。
    • 事实上 RosyWriter 使用kCVPixelFormatType_32BGRA(不是...32RGBA)。
    • 是的!它正在工作!非常感谢!盯着所有这些参数看太久会明显让你参数盲目。
    • @robmayoff 嗨,请您看看我的问题。 thx.stackoverflow.com/questions/37611593/…
    猜你喜欢
    • 1970-01-01
    • 2019-03-19
    • 2016-09-23
    • 2018-06-08
    • 2014-02-01
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2010-10-27
    相关资源
    最近更新 更多