#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():Failed to recognize of the file "lena.jpg“show up.Any suggestion?
我安装了imageMagick,但错误仍然出现。
发布于 2015-09-04 14:42:35
要在CImg中启用原生JPG文件支持,请在包含CImg.h之前使用此选项。
#define cimg_use_jpeg
#include "CImg.h"
....并将您的代码与libjpeg库链接起来。它对我来说是完美无瑕的。如果您不使用它,CImg将尝试外部调用ImageMagick的转换工具来加载文件,这不是最干净的解决方案。在CImg中使用libjpeg无疑更好。对于其他图像格式(tiff、png等)也是如此。
发布于 2015-09-04 13:15:44
你有没有尝试过"lena.jpg“以外的其他图像文件?"lena.jpg“是否与当前程序在同一目录中?你用的是什么编译器?
这个例子能工作吗(如果能工作,那就没什么意义了)?
#include "CImg.h"
using namespace cimg_library;
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 };
image.blur(2.5);
CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
while (!main_disp.is_closed() && !draw_disp.is_closed()) {
main_disp.wait();
if (main_disp.button() && main_disp.mouse_y()>=0) {
const int y = main_disp.mouse_y();
visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.width()-1,y,0,0),red,1,1,0,255,0);
visu.draw_graph(image.get_crop(0,y,0,1,image.width()-1,y,0,1),green,1,1,0,255,0);
visu.draw_graph(image.get_crop(0,y,0,2,image.width()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp);
}
}
return 0;
}来源:http://cimg.eu/reference/group__cimg__tutorial.html
我注意到文档说如果安装了imageMagick,它只支持jpg,也许你在那里做错了什么,它没有正确安装?
编辑:
这行得通吗?
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> img(640,400,1,3); // Define a 640x400 color image with 8 bits per color component.
img.fill(0); // Set pixel values to 0 (color : black)
unsigned char purple[] = { 255,0,255 }; // Define a purple color
img.draw_text(100,100,"Hello World",purple); // Draw a purple "Hello world" at coordinates (100,100).
img.display("My first CImg code"); // Display the image in a display window.
return 0;
}发布于 2018-09-19 00:44:41
对我来说起作用的是使用文件的绝对路径,而不仅仅是文件名:
例如。修改为: CImg图像(“lena.jpg”),visu(500,400,1,3,0);
对此: image("C:\Users\youruser\Desktop\lena.jpg"),CImg visu(500,400,1,3,0);
当然,根据文件存放位置的不同,此路径也会有所不同。
https://stackoverflow.com/questions/32390318
复制相似问题