c++image-processingimagemagickcimg

How to enable libMagick++ in order to save .png file format


I have written a c++ program that read, add noise and save image. I can save image in .bmp but when try to save image in .png, the error pops up saying ...Unable to save file 'noisy-canon.png' unless libMagick++ is enabled

See my code below

#include <iostream>
#include <algorithm>
#include <vector>
#include <Magick++.h>
#include <CImg.h>

using namespace std;
using namespace cimg_library;

int main()
{
        //image file
        CImg<unsigned char> image("milla.png");
        image.noise(5,2);
        image.save_magick("noisy-canon.png");
        CImgDisplay main_disp(image, "Image with Pepper noise",0);
        while (!main_disp.is_closed())
            {
                main_disp.wait();
            }
        getchar();
        return 0;
}

I also tried to use save_cimg(). It creates a file, with error saying

...Unable to save compressed data in file 'noisy_canon.png' unless zlib is enabled, saving them uncompressed.

Below is my code;

(...)

image.save_cimg("noisy_canon.png",1);

(...)

Below attempts where tried with no success;

//above cimg.h "this gives error"
#define cimg_use_png  
#include <CImg.h>

//tried below cimg.h "no error, but doesn't work"
#include <CImg.h>
#define cimg_use_png

Thanks in advance


Solution

  • I find out the alternative to libMagick++. Since it is installed on the machine, I used the terminal/command version to convert.

    system("convert input.jpg output.png");