Search code examples
c++visual-studio-2015jpegdata-conversioncimg

CImg save_jpeg() does not work


I have a problem with CImg. I want to convert .bmp file to .jpg one.

#include "CImg.h"
using namespace cimg_library;
(...)
CImg<unsigned char> image("image.bmp");
image.save_jpeg("image.jpg", 60);

When I want to run this program, sometimes it return an error: CImag error

Sometimes it did not appear, but also did not create .jpg file.

I want to add, that another CImg functions works properly, like turning photo to a grayscale.

Could you please tell me what is wrong with this code? Maybe it is another possible way to convert and save photo into .jpg file?

EDIT: When I add

#define cimg_use_jpeg

before

#include <CImg.h>

I got a lot of errors regarding cimg.h error


Solution

  • Try adding this line before your #include "CImg.h"

    #define cimg_use_jpeg 1
    

    It tells CImg to use its own internal JPEG encoder/decoder rather than ImageMagick which you may not have installed.

    For the sake of completeness, there is also:

    #define cimg_use_tiff 1
    #define cimg_use_png 1