开源库CImg 数据格式存储之二(RGB 顺序)

在上一篇博客中已经初步说明了GDI和CImg数据的存储格式感谢博友 Imageshop 评论说明

CImg的说明文档中已有详细说明(详见上篇博客说明)

CImg的数据格式确实是RRRGGGBBB顺序存储的已经毫无疑问,但是其参考手册中对其他GDI

的数据格式说明是略有瑕疵,参考手册说其他GDI的数据格式是RGBRGBRGB,其实则不是经过验证

bmp类型的数据格式应该是BGRBGRBGR 下面用code验证

说明:使用MFC 同时用CImage和CImg加载同一幅图片

void ImageIO::loadImage(const BiCImg & image, T*& pImagePlane,int& width,int& height,int& nchannels)
{
    // get the image information
    
    width=image.width();
    height=image.height();
    nchannels=3;
    int rgb_leng=width*height;
    pImagePlane=new T[width*height*nchannels];

    // check whether the type is float point
    bool IsFloat=false;
    if(typeid(T)==typeid(double) || typeid(T)==typeid(float) || typeid(T)==typeid(long double))
        IsFloat=true;
    
    const unsigned char* plinebuffer;
    plinebuffer=image.data(0,0);
    for(int i=0;i<height;i++)
    {        
        //plinebuffer=image.scanLine(i);
        for(int j=0;j<width;j++)
        {
                        
pImagePlane[(i*width+j)*3]=plinebuffer[i*width+j+2*rgb_leng];//RGB b
                pImagePlane[(i*width+j)*3+1]=plinebuffer[i*width+j+rgb_leng];//RGB g
                pImagePlane[(i*width+j)*3+2]=plinebuffer[i*width+j];//RGB r
            
        }
    }
}

上述为正确的顺序,若改为如下代码

                pImagePlane[(i*width+j)*3]=plinebuffer[i*width+j];//RGB r 

                pImagePlane[(i*width+j)*3+1]=plinebuffer[i*width+j+rgb_leng];//RGB g

           pImagePlane[(i*width+j)*3+2]=plinebuffer[i*width+j+2*rgb_leng];//RGB b

实验效果如下图

 

右图为原始图片,明显左图的蓝色部分取代了原始图片的红色应该是BGR缺写成了RGB 

 

转载于:https://www.cnblogs.com/sheshouyanhun/p/3270415.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值