如何使用 RGB 数据创建 CGImage?
谁能告诉我一个如何使用的清晰示例
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
);
我有一个 CGFloat dataBuffer [width * height * 3];
它包含图像的所有 RGB 数据。本质上,它从像素 R (0,0)、G (0,0)、B(0,0)、R(0,1)... 到 R(宽度、高度)、G(宽度、高度) , B(宽度,高度)
我知道图像的尺寸,宽度x高度。我如何使用我所拥有的信息并创建 CGImage?
请帮忙,谢谢
我发布了另一个包含上述问题的问题。 nschmidt 正确回答了,这里是链接
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];
It contains all of the RGB data of the image. 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)
I know the size of the image, width x height. How do I use the information that I have and create and CGImage??
Please help, thanks
I posted another question that encompasses the above question. It was answered correctly by nschmidt, here is the link
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其中最大的谜团是数据提供者。答案是您需要创建一个 CGDataProvider 对象,该对象要么包含或可以提供您拥有的像素数据。
一些不太神秘的事情是传递给
colorSpace
和bitmapInfo
的内容。它们是一个 CGColorSpace 对象和一个 CGBitmapInfo 位掩码。decode
数组的解释可能会更清楚,但明确的是您可能不需要它。传递NULL
。除了这些之外,一切都是不言而喻的,或者在 中得到了很好的解释该函数的文档。
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.
Some lesser mysteries are what to pass for
colorSpace
andbitmapInfo
. Those are a CGColorSpace object and a CGBitmapInfo bit-mask.The explanation of the
decode
array could be clearer, but what is clear is that you probably don't need one. PassNULL
.Aside from those things, everything is either self-evident or well-explained in the documentation for this function.
我发布了包含上述问题的另一个问题。 nschmidt 正确回答了,这里是链接
在 Objective-C++ Cocoa 中将 RGB 数据转换为位图
I posted another question that encompasses the above question. It was answered correctly by nschmidt, here is the link
Converting RGB data into a bitmap in Objective-C++ Cocoa