美文网首页
RGBA到UIImage的转换

RGBA到UIImage的转换

作者: matlab2000 | 来源:发表于2017-04-18 16:39 被阅读0次

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

    相关文章

      网友评论

          本文标题:RGBA到UIImage的转换

          本文链接:https://www.haomeiwen.com/subject/fcqqzttx.html