在YUV中绘制CGImageRef [英] Drawing CGImageRef in YUV

查看:172
本文介绍了在YUV中绘制CGImageRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用代码在OS X上将CGImageRef转换为CVPixelBufferRef.

I am using the code here to convert a CGImageRef into a CVPixelBufferRef on OS X .

将UIImage转换为CVImageBufferRef

但是,我需要在YUV (kCVPixelFormatType_420YpCbCr8Planar)中而不是现在的RBG中绘制图像.

However, I need the image to be drawn in YUV (kCVPixelFormatType_420YpCbCr8Planar) instead of RBG as it is now.

无论如何,是否可以在YUV色彩空间中直接绘制CGImage?如果不是,是否有人能提供将CVPixedBufferRef RBG 转换为 YUV 的最佳方法的例子?

Is there anyway to directly draw a CGImage in YUV colorspace? And if not, does anyone have an example for the best way to go about converting the CVPixedBufferRef from RBG into YUV?

我了解转换的公式,但是在CPU上进行转换的速度非常慢.

I understand the formulas for the conversion but doing it on the CPU is painfully slow.

推荐答案

使用以下方法找出答案:

Figured it out using:

CVPixelBufferRef converted_frame;

CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_420YpCbCr8Planar, 0, &converted_frame);

VTPixelTransferSessionTransferImage(_vtpt_ref, imageBuffer, converted_frame);

其中imageBuffer是来源CVPixedBufferRef

这篇关于在YUV中绘制CGImageRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆