开源库CImg 数据格式存储

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

相关文章
相关标签/搜索