• Dalsa CProImage转CImage(MFC)


    自己封装了一个函数,仅供参考

    void ToCImage(CProImage cProImage,CImage* cImage) //函数封装,注意指针传参
    {
        CProImage cR,cG,cB;
        int width=cProImage.GetWidth();
        int height=cProImage.GetHeight();
        int channels;//通道
    
        if (cProImage.GetFormat()==CProData::FormatUByte)
        {
            channels=1;
        }else
        {
            channels=3; //彩色图需拆分后分别转换。
            cProImage.Split(&cR,&cG,&cB);
        }
    
        cImage->Create(width,height,8*channels);
    
        int pit=cImage->GetPitch();   //行与行的间距
        int bitCount=cImage->GetBPP()/8;
    
        BYTE* pImg=(BYTE*)cImage->GetBits(); //指向位图缓存
    
        for (int i=0;i<height;++i)
        {
            for (int j=0;j<width;++j)
            {
                if (channels==1)
                {
                    *(pImg+pit*i+j*bitCount)=(int)cProImage.GetData(j,i);
                }
                if (channels==3) //注意BGR顺序
                {
                    *(pImg+pit*i+j*bitCount)=(int)cB.GetData(j,i);
                    *(pImg+pit*i+j*bitCount+1)=(int)cG.GetData(j,i);
                    *(pImg+pit*i+j*bitCount+2)=(int)cR.GetData(j,i);
                }
    
            }
        }
        if (channels==1)
        {
            //CImage的数据其实是调色板的索引值,所以必须有调色板,否则全黑。注意彩色图不需要调色板
            RGBQUAD colors[256];
            cImage->GetColorTable(0, cImage->GetMaxColorTableEntries(), colors);
            for (int i = 0; i < 256; i++)
            {
                colors[i].rgbBlue = (BYTE)i;
                colors[i].rgbGreen = (BYTE)i;
                colors[i].rgbRed = (BYTE)i;
                colors[i].rgbReserved = 0; //为了压缩数据,使用24位表示一个像素,不保存透明值(alpha分量),所以使用rgbReserved。既然是保留不用的,设置成多少都可以。但是一般设置成0。
            }
            cImage->SetColorTable(0, cImage->GetMaxColorTableEntries(), colors);
        }
    }
  • 相关阅读:
    The archive: D:/Program Files (x86)/apache-tomcat-6.0.39/bin/bootstrap.jar w
    DTO
    关于REST的JSON格式
    extjs renderer function参数设置
    转::持久化实体persist()--往数据表中插入数据
    使用Ext.define自定义类
    转::Ext.getCmp()应用
    【转】VO DAO BO
    JPA的查询语言:JPQL的命名查询 @NamedQuery
    11.25 冒泡事件 form表单事件
  • 原文地址:https://www.cnblogs.com/xixixing/p/14230776.html
Copyright © 2020-2023  润新知