I've been looking for a code in C++ which gets me the RGB values of all pixels of a png file.
So I searched a lot through the internet and found different ways of doing such a thing, like using libpng , OpenCV, Magick++, CImg , etc. and I just decided to go with the CImg one (mostly because I don't know how to use OpenCV although I searched a lot about how to install and use it in Code::Blocks and it just has something to do with mingw64 which the installer I downloaded from Sorceforge, keeps giving me errors in the middle of downloading some files, and about the rest of them I just can't find the appropriate header file (like Magick++.h) which's compatible with Code::Blocks... So if you think some of these would be better and simpler than CImg.h, then I'd appreciate if you provided me a download link of the header or any other necessary thing)
So here is the code I found with Cimg :
#include <windows.h>
#include <iostream>
using namespace std;
#include <CImg.h>
using namespace cimg_library;
int main()
{
CImg<unsigned char>src("twittericon.png");
int width = src.width();
int height = src.height();
cout << width << "x" << height << endl;
for (int r = 0; r < height; r++)
for (int c = 0; c < width; c++)
cout << "(" << r << "," << c << ") ="
<< " R" << (int)src(c,r,0,0)
<< " G" << (int)src(c,r,0,1)
<< " B" << (int)src(c,r,0,2) << endl;
return 0;
}
But the problem is after running the program, it gives me the error : CImg::load(): Failed to recognize format of file 'twittericon.png'
What should I do with the error?
And by the way, do you know any better way to read these RGB values of a png file? If you do, could you please also provide me a little bit of an instruction for it? Thanks.