纹理转PixelBuffer 调试用

本文介绍了一个Objective-C方法,用于根据指定尺寸创建兼容OpenGL ES的CVPixelBuffer,并利用CIContext将CIImage渲染到该缓冲区中。此方法首先定义了必要的属性和配置选项,然后创建缓冲区,最后使用当前的EAGLContext进行渲染。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-(CVPixelBufferRef)createPixelBufferWithSize:(CGSize)size {
    const void *keys[] = {
        kCVPixelBufferOpenGLESCompatibilityKey,
        kCVPixelBufferIOSurfacePropertiesKey,
    };
    const void *values[] = {
        (__bridge const void *)([NSNumber numberWithBool:YES]),
        (__bridge const void *)([NSDictionary dictionary])
    };
    
    OSType bufferPixelFormat = kCVPixelFormatType_32BGRA;
    
    CFDictionaryRef optionsDictionary = CFDictionaryCreate(NULL, keys, values, 2, NULL, NULL);
    
    CVPixelBufferRef pixelBuffer = NULL;
    CVPixelBufferCreate(kCFAllocatorDefault,
                        size.width,
                        size.height,
                        bufferPixelFormat,
                        optionsDictionary,
                        &pixelBuffer);
    
    CFRelease(optionsDictionary);
    
    return pixelBuffer;
}
    CVPixelBufferRef pixelBuffer1 = [self createPixelBufferWithSize: CGSizeMake(540, 960)];

    static CIContext *_ciContext;
    CIImage *outputImage = [CIImage imageWithTexture:textureId size:CGSizeMake(540, 960) flipped:YES colorSpace:NULL];
    if( outputImage != nil) {
        if( _ciContext == nil) {
            _ciContext = [CIContext contextWithEAGLContext: [EAGLContext currentContext]  options:@{kCIContextWorkingColorSpace : [NSNull null]} ];
        }
       
        [_ciContext render: outputImage toCVPixelBuffer: pixelBuffer1  bounds:[outputImage extent] colorSpace:NULL];
    }
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值