Tested on Ubuntu 10.04 with a handmade 3x3 RGB image saved as test.png
:
sudo apt-get install cimg-dev
Source file cimg_test.cpp
:
#include <iostream>
using namespace std;
#include <CImg.h>
using namespace cimg_library;
int main()
{
CImg<unsigned char> src("test.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;
}
Compile and run:
g++ cimg_test.cpp -lX11 -lpthread -o cimg_test
./cimg_test
3x3
(0,0) = R0 G0 B0
(0,1) = R255 G0 B0
(0,2) = R0 G255 B0
(1,0) = R0 G0 B255
(1,1) = R128 G128 B128
(1,2) = R0 G0 B128
(2,0) = R128 G0 B0
(2,1) = R0 G128 B0
(2,2) = R255 G255 B255
It works.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…