我正在编写用于在 VC++ 中缩小图像的代码。当我保存目标位图时,它会给出单色图像。代码:
int iNewWidth = 400;
int iNewHeight = 500;
CImage image;
HRESULT rs=image.Load(_T("E:\\input.jpg"));
int a=10;
CDC destDC;
int res=destDC.CreateCompatibleDC(NULL);
HDC hdcDest=HDC(destDC);
HBITMAP hDestBitmap=CreateCompatibleBitmap(hdcDest, iNewWidth, iNewHeight);
HBITMAP hOldBitmap=(HBITMAP)SelectObject(hdcDest,hDestBitmap);
SetStretchBltMode(hdcDest,BLACKONWHITE);
BOOL bl=image.StretchBlt(hdcDest,0, 0, iNewWidth, iNewHeight, 0, 0, image.GetWidth(), image.GetHeight(), SRCERASE);
HRESULT res2;
CImage new_image;
new_image.Attach(hDestBitmap);
res2=new_image.Save(_T("E:\\NewImage.jpg"));
HBITMAP hb=new_image.Detach();
ReleaseDC(NULL,hdcDest);
如果有人在这里帮助我,我将非常感激。提前致谢