[英]How do I create a CGImage with RGB data?
Can anyone show me a clear example of how to use任何人都可以向我展示如何使用的清晰示例
CGImageRef CGImageCreate
(
size_t width,
size_t height,
size_t bitsPerComponent,
size_t bitsPerPixel,
size_t bytesPerRow,
CGColorSpaceRef colorspace,
CGBitmapInfo bitmapInfo,
CGDataProviderRef provider,
const CGFloat decode[],
bool shouldInterpolate,
CGColorRenderingIntent intent
);
I have a CGFloat dataBuffer [width * height * 3];我有一个 CGFloat dataBuffer [width * height * 3];
It contains all of the RGB data of the image.它包含图像的所有 RGB 数据。 Essentially, it goes from pixel R (0,0), G (0,0), B(0,0), R(0,1)... to R(width, height), G(width,height), B(width,height)本质上,它从像素 R (0,0), G (0,0), B(0,0), R(0,1)... 到 R(width, height), G(width,height) , B(宽度,高度)
I know the size of the image, width x height.我知道图像的大小,宽 x 高。 How do I use the information that I have and create and CGImage??我如何使用我拥有和创建的信息和 CGImage?
Please help, thanks请帮忙,谢谢
I posted another question that encompasses the above question.我发布了另一个包含上述问题的问题。 It was answered correctly by nschmidt, here is the link nschmidt 回答正确,这里是链接
Converting RGB data into a bitmap in Objective-C++ Cocoa 在 Objective-C++ Cocoa 中将 RGB 数据转换为位图
The biggest mystery there is the data provider.最大的谜团是数据提供者。 The answer for that is that you need to create a CGDataProvider object that either contains or can provide the pixel data you have.答案是您需要创建一个CGDataProvider对象,该对象包含或可以提供您拥有的像素数据。
Some lesser mysteries are what to pass for colorSpace
and bitmapInfo
.一些较小的谜团是传递给colorSpace
和bitmapInfo
。 Those are a CGColorSpace object and a CGBitmapInfo bit-mask.这些是一个CGColorSpace对象和一个CGBitmapInfo位掩码。
The explanation of the decode
array could be clearer, but what is clear is that you probably don't need one.对decode
数组的解释可能更清楚,但很清楚的是,您可能不需要一个。 Pass NULL
.传递NULL
。
Aside from those things, everything is either self-evident or well-explained in the documentation for this function .除了这些,在这个函数的文档中,一切都是不言而喻的或很好解释的。
I posted another question that encompasses the above question.我发布了另一个包含上述问题的问题。 It was answered correctly by nschmidt, here is the link nschmidt 回答正确,这里是链接
Converting RGB data into a bitmap in Objective-C++ Cocoa 在 Objective-C++ Cocoa 中将 RGB 数据转换为位图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.