使用jpeglib的CImg [英] CImg with jpeglib

查看:95
本文介绍了使用jpeglib的CImg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使CImg与Visual Sudio 2017和jpeg-9b一起使用,但是由于某种原因,它无法使用.

I'm trying to make CImg work with Visual Sudio 2017 and jpeg-9b but for some reason it doesn't.

代码:

#define cimg_use_jpeg
#include "../CImg/CImg.h"
using namespace cimg_library;

#pragma comment(lib, "libjpeg.a")

CImg<unsigned char> image("../images/img.jpg"), visu(500, 400, 1, 3, 0);

第一步是构建库,在此我遵循了如何使用MinGW 编译器的说明.即使构建成功,生成的库 libjpeg.a 在Visual Studio解决方案中不可链接.错误消息:

The first step is the build of the library, where I followed a description how to use the MinGW compiler. Even if the build succeeds, the generated library libjpeg.a is not linkable in the Visual Studio solution. Error Message:

状态错误LNK2019未解析的外部符号__imp___iob在函数_output_message中引用

State Error LNK2019 unresolved external symbol __imp___iob referenced in function _output_message

另一个生成的库 libjpeg.dll.a 在加载.jpg文件时引发错误 CImg异常(图片)

Another generated library libjpeg.dll.a throws an error when loading a .jpg file CImg Exception (picture)

经过几次重建后,问题仍然存在.我也尝试使用VC编译器,但是找不到调用构建 comand nmake -f makefile.vc setup-v10 时所需的必需的 win32.mak 文件..该文件的非官方下载无法在我的电脑上正常工作.无法在Visual Studio中打开生成的解决方案.

After a couple of rebuilds the issue still exists. I also tried to use the VC compiler, but I cannot find the needed win32.mak file which is required when calling the build comand nmake -f makefile.vc setup-v10. Unofficial downloads of this file don't work properly on my pc. The generated solution cannot be opened in Visual Studio.

是否有一些解决方法-如果没有解决方案?

Is there maybe some workaround - if there is not a solution?

推荐答案

如果要使用 CImg 读/写JPEG图像,则有几种选择:

You have several options if you want to read/write JPEG images with CImg:

您可以安装 libjpeg ,我已经在此处进行了详细介绍.如果遵循此选项,则必须使用:

You can either install libjpeg which I have already covered in some detail here. If you follow this option, you must use:

#define cimg_use_jpeg

CImg 将针对 libjpeg 进行编译和链接,并读取和写入JPEG图像.您需要编译并安装 libjpeg 才能使用此选项.

and CImg will compile and link against libjpeg and read and write JPEG images. You will need to have compiled and installed libjpeg to use this option.

您可以安装 ImageMagick ,并且 CImg 可以委派对它的读写.如果选择此路线,请确保在安装 ImageMagick 的过程中,选中标题为安装旧版命令" 或类似内容的框.使用此选项,您可以读取和写入JPEG以外的大约200种其他图像格式.这对于生成测试图像和尝试算法而无需编写任何C ++也是非常有用的.主要缺点是分布范围很大.

You can install ImageMagick and CImg can delegate reading and writing to it. If you choose this route, be sure to tick the box entitled "Install legacy commands" or similar, during installation of ImageMagick. This option gives you the benefit of being able to read and write about 200 other image formats in addition to JPEG. It is also very useful for generating test images and trying out algorithms without needing to code any C++. The main downside is that it is quite a large distribution.

如果要使用此选项,则不能 #define cimg_use_jpeg #define cimg_use_magick . CImg 将在运行时查找 ImageMagick convert.exe magick.exe >和 ImageMagick 不会为您的 Visual Studio 项目所了解,或与之无关.您可以致电:

If you want to use this option, you must not #define cimg_use_jpeg nor #define cimg_use_magick. CImg will look for the convert.exe or magick.exe of ImageMagick at runtime and ImageMagick will not be known to, or involved with your Visual Studio project. You can call:

imagemagick_path()

在运行时告诉 CImg 您已安装 ImageMagick convert.exe magick.exe 的位置.如果使用此选项,则在保存图像时应使用通用的 save()方法,而不是 save_jpeg() save_png().

to tell CImg at runtime where you have installed ImageMagick's convert.exe or magick.exe. If you use this option, you should use the generic save() method when saving images, rather than save_jpeg() or save_png().

到目前为止,这是最简单的选择.

This is, by far, the easiest option.

如果要使用此选项,则必须执行以下操作:

If you want to use this option, you must do:

#define cimg_use_magick

然后 CImg 将编译并链接到 Magick ++ - ImageMagick 的C ++接口.这将需要您安装 Magick ++ 的源代码,并且可能是最难实现的选择.

and then CImg will compile and link with Magick++ - the C++ interface to ImageMagick. This will require you to have installed the source code for Magick++ and is probably the hardest option to achieve.

根据您的目标,可以想到安装更简单,重量更轻的 NetPBM 工具,并将图像转换为 PBM/PGM/PPM 格式,因为CImg 可以在根本不需要任何外部库的情况下原生地进行读写.

Depending on your goals, you could conceivably install the much simpler, lighter weight, NetPBM tools and convert your images to PBM/PGM/PPM format since CImg can natively read and write those without any external libraries at all.

可以想象,您可以在加载图像时使用C ++的 system()动态地执行此操作.

You could, conceivably, use C++'s system() to do this dynamically when loading images.

这篇关于使用jpeglib的CImg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆