2

Hi i am using cimg to process images in c++ with Xcode, but whenever i try to load an image it fails to do so. I have placed the image in the same directory as the project, and besides that i have even specified the filepath. I have also installed Imagemagick as i am told that cimg needs this to work with jpegs. But a simple piece of code like this:

#include "CImg.h"
#include <stdlib.h>
#include <iostream>
#define cimg_use_magick
#define cimg_use_png
using namespace cimg_library;
using namespace std;

int main()
{
CImg<unsigned char> img("ILTQq.png");
img.display();
}

still fails. So i am thinking that maybe i haven't linked imagemagick properly with xCode, but this code fails even when i try a .png format which to my knowledge is supported by CImg without any additional "help". What should i do?

Endi Zhupani
  • 736
  • 2
  • 7
  • 22
  • Can you please provide a sample code? It's hard to solve problem of a code one can't look at. – ilgaar Jan 17 '15 at 12:03
  • sorry, i've added the code above. – Endi Zhupani Jan 17 '15 at 12:10
  • 1
    And the file `ILTQq.png` is in the current working directory when you run the program? The project directory and the programs working directory doesn't have to be the same. Check the project settings for the working directory. – Some programmer dude Jan 17 '15 at 12:12
  • i think it found the image file, but it still can't recognise it's format. As i mentioned earlier i have installed imagemagick so what else do i need to do to make it recognise the format? – Endi Zhupani Jan 17 '15 at 12:48
  • I agree with _Joachim Pileborg_ check if the **image is in the same directory as the _executable program_.** – ilgaar Jan 17 '15 at 13:03
  • I changed the working directory to where the files are and now it shows a different error " Failed to recognise the file format" whereas before it showed "Failed to load file". what should i do? – Endi Zhupani Jan 17 '15 at 13:06
  • Have a look at, and maybe vote for, my answer here... http://stackoverflow.com/a/30951784/2836621 – Mark Setchell Jun 20 '15 at 08:12
  • Did you ever get this working? – Mark Setchell Sep 04 '15 at 13:47
  • Just noticed... you need to `#define cimg_use_magick` and `#define cimg_use_png` **before** `#include "CImg.h"` – Mark Setchell Sep 08 '17 at 10:36

0 Answers0