在 C++ 中转换 RGB 值数组的最简单方法是什么?到图像文件中?
我一直在网上寻找一个好的、快速的解决方案,但还没有找到令我满意的东西。看起来它应该是微不足道的——只需对某个库中的函数进行一两次调用就可以了——但事实似乎并非如此。 libjpeg 和 libtiff 缺乏良好的文档,人们发布的解决方案涉及了解图像的生成方式和编写约 50 行代码。你们会如何在 C++ 中做到这一点?
I've been looking all over the net for a good, quick solution to this, and haven't found anything that has satisfied me yet. It seems like it should be trivial--just one or two calls to a function in some library and that's it--but that doesn't seem to be the case. libjpeg and libtiff lack good documentation and the solutions people have posted involve understanding how the image is produced and writing ~50 lines of code. How would you guys do this in C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要“简单”而不是其他,请查看 stb_image_write.h。
这是一个单一头文件,包括对写入 BMP、PNG 和 TGA 文件的支持。每种格式只需一次调用:
If you want "simple" over anything else, then have a look at stb_image_write.h.
This is a single header file, which includes support for writing BMP, PNG and TGA files. Just a single call for each format:
最简单的方法是将其保存为 Netpbm 图像。假设您的数组被打包为每像素 24 位,像素之间没有填充,那么您可以写出一个超级简单的标头,后跟二进制数据。例如:
The easiest way is to save it as a Netpbm image. Assuming that your array is packed into 24 bits per pixel with no padding between pixels, then you can write out a super-simple header followed by the binary data. For example:
在我的 Graphin 库中,您可以找到简单的函数:
执行此转换。请参阅 http://code.google.com/ p/graphin/source/browse/trunk/src/imageio.cpp#412
库:http://code.google.com/p/graphin/
In my Graphin library you can find simple function:
that does this conversion. See http://code.google.com/p/graphin/source/browse/trunk/src/imageio.cpp#412
The library: http://code.google.com/p/graphin/