RGBA到UIImage的转换

2017-04-18  本文已影响0人  matlab2000

RGBA格式使用ffmpeg很容易生成,

case AV_PIX_FMT_RGBA:

    dataLen = width*height * 4;

    /*ptr is pFrameYUV->data[0] 4 w*h */

然后到UIImage的转换如下:

buf保存了RGBA数据

int bytes_per_pix = 4;

int width = size.width;

int height = size.height;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef newContext = CGBitmapContextCreate(buf,

width, height, 8,

width * bytes_per_pix,

colorSpace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast);

CGImageRef frame = CGBitmapContextCreateImage(newContext);

image = [UIImage imageWithCGImage:frame];

CGImageRelease(frame);

CGContextRelease(newContext);

CGColorSpaceRelease(colorSpace);

上一篇 下一篇

猜你喜欢

热点阅读