根据char* 图像数据指针存储图像

来源:互联网 发布:perl高效编程 pdf 编辑:程序博客网 时间:2024/05/22 15:29
//存图bool SaveImage(LONG ImageWidth, LONG ImageHeight, CHAR* pImageData, BSTR bstrImageSavePath){    CImage pImage;    if(!pImage.IsNull())        pImage.Destroy();    pImage.Create(ImageWidth,ImageHeight,8);    RGBQUAD* ColorTable;    int MaxColors=256;    ColorTable=new RGBQUAD[MaxColors];    pImage.GetColorTable(0, MaxColors, ColorTable);    for(int i=0;i<MaxColors;i++)    {        ColorTable[i].rgbBlue=(BYTE)i;        ColorTable[i].rgbGreen=(BYTE)i;        ColorTable[i].rgbRed=(BYTE)i;    }    pImage.SetColorTable(0,MaxColors,ColorTable);    delete []ColorTable;    UCHAR* pImg=(UCHAR*)pImage.GetBits();    int step=pImage.GetPitch();    for(int i=0;i<ImageHeight;i++)    {           for(int j=0;j<ImageWidth;j++)        {            int iData=*pImageData++;            *(pImg+i*step+j)=iData;        }    }    CString strSavePath((LPCTSTR)bstrImageSavePath);    pImage.Save(strSavePath);    return true;}
原创粉丝点击