CImg: Failed to recognize the jpg format

后端 未结 3 1697
傲寒
傲寒 2021-01-13 14:08
#include 
#include 
#include \"CImg.h\"

using namespace cimg_library;
using namespace std;

int main(){
CImg im         


        
3条回答
  •  臣服心动
    2021-01-13 14:53

    Have you tried any other image files other then "lena.jpg"? Is "lena.jpg" in the same directory than the current program? What compiler you using?

    Does this example work (wouldn't really make sense if it did though)?

    #include "CImg.h"
    using namespace cimg_library;
    int main() {
      CImg 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;
    }
    

    Source: http://cimg.eu/reference/group__cimg__tutorial.html

    I noticed the documentation says it only supports jpg's if imageMagick is installed, perhaps you did something wrong there and it isn't properly installed?

    EDIT:

    Does this work?

    #include "CImg.h"
    using namespace cimg_library;
    int main() {
      CImg 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;
    }
    

提交回复
热议问题