CImg爲開源圖像處理庫,僅有一個頭文件CImg.h便包含了對圖像的全部處理函數,函數操做簡單,編程方便,但國內使用者較少ios
其homepage:http://cimg.sourceforge.net/編程
一般windows的CImage 或nokia的QT中的Qimage 對圖片的存儲均爲按照每一個像素的RGB循序:windows
例如:像素點(0,0)(0,1)(0,2) 在內存中存儲順序爲R1 G1 B1 R2 G2 B2 R3 G3 B3函數
可是CImg中的存儲卻不一樣像素點(0,0)(0,1)(0,2) 在內存中存儲順序爲R1 R2 R3 G1 G2 G3 B1 B2 B3spa
#include <iostream> using namespace std; #include "CImg.h" using namespace cimg_library; #include <iomanip> int main() { CImg<unsigned char> image("car.bmp"); int rgb_leng = image.width()*image.height(); unsigned char *ptr = image.data(0,0); unsigned char *ptest = new unsigned char[rgb_leng*3]; int width = image.width(); int height = image.height(); for(int i=0;i<height;i++) { for(int j=0;j<width;j++) { ptest[i*width+j]=ptr[i*width+j]; ptest[i*width+j+rgb_leng]=ptr[i*width+j+rgb_leng]; ptest[i*width+j+rgb_leng*2]=ptr[i*width+j+rgb_leng*2]; } } CImg<unsigned char> imtest(ptest,width,height,1,3); cout<<"size of iamge"<<image.size()<<endl; cout<<"size of copy iamge"<<imtest.size()<<endl; imtest.save("test.bmp"); image.display("test"); return 0; }
因爲CImg庫剛剛看了一天,不免會誤解其中含義,以上僅表明我的觀點。.net