纹理转PixelBuffer 调试用

来源:互联网 发布:天刀客户端网络异常 编辑:程序博客网 时间:2024/06/14 07:02
-(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];    }