从 RGB 数据创建图像?
我真的遇到了麻烦。我有一些原始 RGB 数据,值从 0 到 255,想将其显示为 iPhone 上的图像,但不知道如何操作。有人可以帮忙吗?我想我可能需要使用 CGImageCreate 但就是不明白。尝试查看课程参考资料,感觉很困难。
我想要的只是通过一些计算生成的 10x10 灰度图像,如果有一种简单的方法来创建 png 或其他东西,那就太好了。
I'm having real trouble with this. I have some raw rgb data, values from 0 to 255, and want to display it as an image on the iphone but can't find out how to do it. Can anyone help? I think i might need to use CGImageCreate but just don't get it. Tried looking at the class reference and am feeling quite stuck.
All I want is a 10x10 greyscale image generated from some calculations and if there is an easy way to create a png or something that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个非常原始的示例,类似于 Mats 的建议,但此版本使用外部像素缓冲区 (
pixelData
):a terribly primitive example, similar to Mats' suggestion, but this version uses an external pixel buffer (
pixelData
):使用
CGBitmapContextCreate()
为自己创建一个基于内存的位图。然后调用 CGBitmapContextGetData() 来获取绘图代码的指针。然后用CGBitmapContextCreateImage()
创建一个CGImageRef
。我希望这足以让您开始。
Use
CGBitmapContextCreate()
to create a memory based bitmap for yourself. Then callCGBitmapContextGetData()
to get a pointer for your drawing code. ThenCGBitmapContextCreateImage()
to create aCGImageRef
.I hope this is sufficient to get you started.
在 Mac OS 上,您可以使用 NSBitmapImageRep 来完成此操作。对于iOS来说,似乎有点复杂。我找到了这篇博文:
http:// /paulsolt.com/2010/09/ios-converting-uiimage-to-rgba8-bitmaps-and-back/
On Mac OS you could do it with an NSBitmapImageRep. For iOS it seems to be a bit more complicated. I found this blog post though:
http://paulsolt.com/2010/09/ios-converting-uiimage-to-rgba8-bitmaps-and-back/