-1

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

genpfault
  • 51,148
  • 11
  • 85
  • 139
newblack
  • 73
  • 2
  • 11

1 Answers1

1

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I think that it should help. I cannot check it because now I try to install libjpeg. Without it it does not work. Do you know fast and easy way to install libjpeg? I try to install with the instruction from https://github.com/LuaDist/libjpeg but this instrucion is too complicated. I try to install it for WIndows, VS2015 – newblack Jul 10 '17 at 19:41