如何最轻松地使用 c/c++ 处理 jpg 图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3255074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to process jpg images with c/c++ most easily?
提问by user198729
I want to iterate over each pixel color in a jpg
format image,
我想遍历jpg
格式图像中的每个像素颜色,
which library should I refer to to do this so that the code can be as short as possible?
我应该参考哪个库来做到这一点,以便代码尽可能短?
回答by NG.
I can think of either ImageMagickor CImg. Here is a CImg tutorialfor you. They abstract away a lot of the decompression details and just give you a grid to work with.
我可以想到ImageMagick或CImg。这是给你的CImg 教程。他们抽象了很多解压细节,只是给你一个网格来处理。
If you go with CImg, you only need to use the datacall. You can probably do something like:
如果你使用 CImg,你只需要使用数据调用。您可能可以执行以下操作:
CImg<unsigned char> src("image.jpg");
int width = src.width();
int height = src.height();
unsigned char* ptr = src.data(10,10); // get pointer to pixel @ 10,10
unsigned char pixel = *ptr;
回答by akira
回答by Hernán Eche
I would use Allegro Game Library http://liballeg.org/Allegroit's simple / open source / free / multiplatform, and you can iterate pixel by pixel if you want
我会使用 Allegro 游戏库http://liballeg.org/ Allegro它很简单/开源/免费/多平台,如果你愿意,你可以逐个像素地迭代
回答by rup
回答by bhups
jpeglib is quite a handy library to play with jpegs.
jpeglib 是一个非常方便的使用 jpeg 的库。
回答by ttchong
For access to pixel level information. libjpeg & JAI Image I/O Tools should be sufficient. JAI provide advance image processing framework more than this. All options allow you to read/write pixels to an image file.
用于访问像素级信息。libjpeg 和 JAI 图像 I/O 工具应该足够了。JAI 提供的高级图像处理框架不止于此。所有选项都允许您将像素读/写到图像文件中。
libjpegIn C/C++. It is available for Linux and Window. I have used it in Linux before and it works well. However, if you would like to process other image type, you may need to get other package and learn another API interface.
libjpeg在 C/C++ 中。它适用于 Linux 和 Window。我之前在 Linux 中使用过它,效果很好。但是,如果您想处理其他图像类型,则可能需要获取其他包并学习其他 API 接口。
Java Advanced Imaging(JAI) Image I/O ToolsRemember to download the platform specific java package because there is specific optimization for different system. It covers not only JPG but other image format too with exact same API interface.
Java Advanced Imaging(JAI) Image I/O Tools记得下载平台特定的java包,因为不同的系统有特定的优化。它不仅涵盖 JPG,还涵盖其他图像格式,具有完全相同的 API 接口。
Java Advanced Imaging(JAI)If you plan to do more advance level of processing such as using image operator and filter, you can use this. This is a package provide higher level functionality than JAI Image I/O Tools.
Java Advanced Imaging(JAI)如果您计划进行更高级的处理,例如使用图像运算符和过滤器,您可以使用它。这是一个提供比 JAI Image I/O 工具更高级别功能的包。
EDIT: to remove the 1, 2 & 3 as suggested
编辑:按照建议删除 1、2 和 3