0

I am using CImg to read a .png file, like following:

// DGT.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include "..\CImg\CImg.h"

using namespace std;
using namespace cimg_library;

long ReadImage(char *fileName)
{
    CImg<unsigned char> image(fileName); // stackover flow exceptions thrown here.

    return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
    ReadImage("D:\\Projects\\DGT\\DGT\\shepplogan256.png");
    return 0;
}

However, the stack overflown exceptions is thrown at CImg<unsigned char> image(fileName); when trying to load the image. The image is there, so I am wondering where I messed up and how to read the image?

Ono
  • 1,357
  • 3
  • 16
  • 38

2 Answers2

1

You need libpng or imagemagick to load PNG-Files with CImg.

NaCl
  • 2,683
  • 2
  • 23
  • 37
  • I also tried another .jpeg file, it throws same exception? – Ono Sep 25 '14 at 20:25
  • OK. I guess you are right. I tried to load a .bmp, and there is no problem with that. I guess it means some libraries are missing. Thanks! – Ono Sep 25 '14 at 20:28
  • Yeah... I was a little disappointed since I thought CImg can handle different image types. – Ono Sep 25 '14 at 20:46
  • CImg is not for loading images, its mainly for manipulating them. :) – NaCl Sep 25 '14 at 20:50
  • OK, so who is good at loading different images in c++ then, any chance you can educate me? – Ono Sep 25 '14 at 20:52
  • Still `imagemagick`, if you want many formats. Just `libpng` or `libjpg` for specific. I dunno, your decision. Choose what you want – NaCl Sep 25 '14 at 20:55
0

To read .jpeg or .png files natively, CImg needs you to link your code with either libpng or libjpeg, and that you define macros cimg_use_png or cimg_use_jpeg. By doing so, ImageMagick is not required at all. I prefer this solution as it does not require installing a new (external) software to read image files, and eases the distribution of the binaries as well.