CImg:无法识别jpg格式 [英] CImg: Failed to recognize the jpg format

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

问题描述

#include <iostream>
#include <stdlib.h>
#include "CImg.h"

using namespace cimg_library;
using namespace std;

int main(){
CImg<unsigned char> image("lena.jpg"), visu(500,400,1,3,0);

const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };



return 0;}

当我编译这段代码时,错误:CImg :: load():无法识别文件"lena.jpg"的格式.有什么建议吗?

When i compile this code the error: CImg::load(): Failed to recognize format of the file "lena.jpg" shows up.Any suggestion?

我安装了imageMagick,但错误仍然发生.

I installed the imageMagick but the error still happens.

推荐答案

要在CImg中启用本机JPG文件支持,请将其放在包括CImg.h的位置:

To enable native JPG file support in CImg, put this before including CImg.h:

#define cimg_use_jpeg
#include "CImg.h"
....

,然后将代码链接到libjpeg库.它对我来说完美无缺. 如果您不使用它,CImg将尝试对ImageMagick的转换工具进行外部调用以加载文件,这不是最干净的解决方案.在CImg中使用libjpeg绝对更好. 对于其他图像格式(tiff,png,...)也是如此.

and link your code with the libjpeg library. It works flawlessly for me. If you don't use this, CImg will try to do an external call to ImageMagick's convert tool to load the file, which is not the cleanest solution. Using libjpeg inside CImg is definitely better. That works the same for other image formats (tiff, png, ...).

这篇关于CImg:无法识别jpg格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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