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);