补充一下,是在RELEASE版本下保存成功后出错的,GDI+代码如下:
Graphics graph(*MemDC);
Bitmap image(m_picture.GetBitmap(),NULL);
CLSID encoderClsid;
WCHAR str[128];
memset(str,0,128);
//    wcscpy(string, m_strSub1Text);
int wlen = MultiByteToWideChar(CP_ACP, 0,  sFile, -1,NULL,0);   
MultiByteToWideChar(CP_ACP, 0,  sFile, strlen(sFile)+1,str,wlen);

// USES_CONVERSION;
GetEncoderClsid(L"image/gif",&encoderClsid);
// image.Save(A2W(m_strFile),& encoderClsid);
image.Save(str,&encoderClsid);
Status sta=image.GetLastStatus();
if(sta!=Ok)
{
AfxMessageBox("Save image Failed !");
}

解决方案 »

  1.   

    用CXIMAGE 实现的代码如下: //CxImage image(m_strFile,CXIMAGE_FORMAT_BMP);
     /*
    CxImage image;
    image.CreateFromHBITMAP(m_picture.GetBitmap());

    UINT colors = 250;
    CQuantizer q(colors,(colors>16?7:8));
    q.ProcessImage(image.GetDIB());
    RGBQUAD* ppal=(RGBQUAD*)calloc(256 *sizeof(RGBQUAD),1);
    q.SetColorTable(ppal);
    image.DecreaseBpp(8,true,ppal,256);
    if (ppal) free(ppal);

    image.SetTransIndex(1);
    RGBQUAD c={255,255,255,0};
    image.SetTransColor(c);



    if (image.GetBpp()>8){
    AfxMessageBox("The image will be saved as a true color GIF!\nThis is ok for CxImage, but not for many other programs.\nFor better compatibility, please use DecreaseBpp to 8 bits or less.",MB_ICONINFORMATION);
    return;
    }
    //修改所用颜色数
    //image.head.biClrUsed = image.head.biClrImportant;

    image.Save(sFile,CXIMAGE_FORMAT_GIF);
    image.Destroy();