简体   繁体   English

如何使用CImg库从jpg转换为bmp?

[英]How to convert from jpg to bmp by using CImg library?

I want to convert JPG to BMP file. 我想将JPG转换为BMP文件。 I am using a library called CImg . 我正在使用一个名为CImg的库。
I am using the following code to do the conversion operation: 我正在使用以下代码进行转换操作:

#include "CImg.h"  
using namespace cimg_library;

int main(int argc, char *argv[]) {

    CImg<unsigned char> image("picture.jpg");
    image.save_bmp("imgB.bmp");

    return 0;
}

But the following error occurs: 但是会发生以下错误:

What might be the problem. 可能是什么问题。 Is there something I missed? 有什么我想念的吗?

This problem happens because you have not installed ImageMagick . 发生此问题的原因是您尚未安装ImageMagick

Note that you must also have installed the ImageMagick package in order to be able to read JPG images. 请注意,您还必须安装ImageMagick软件包才能读取JPG图像。

If you are going to install ImageMagick into not standard path, then you will need to specify it's path like below 如果要将ImageMagick安装到非标准路径中,则需要指定它的路径,如下所示

cimg::imagemagick_path("C:\\ImageMagick-6.9.2-Q16\\convert.exe");

If you don't want to install ImageMagick then you should link your code with libjpeg library and enable native JPG file support in CImg, putting this before including CImg.h: 如果您不想安装ImageMagick ,则应将代码与libjpeg库链接,并在CImg中启用本机JPG文件支持,并将其放在包括CImg.h之前:

#define cimg_use_jpeg
#include "CImg.h"

Using CImg with libjpeg is definitely better. libjpeg一起使用CImg绝对更好。 That works the same for other image formats (tiff, png, ...). 对于其他图像格式(tiff,png,...),效果相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM