//Scale the SrcBitmap, with destWidth*destHeight
int destHeight)
3: {
4: BITMAP bitmapInfo;
5: pSrcBitmap->GetBitmap(&bitmapInfo);
int srcWidth = bitmapInfo.bmWidth;
int srcHeight = bitmapInfo.bmHeight;
8:
9: HDC hScreenDC = ::GetDC(NULL);
10: CDC* pScreenDC = CDC::FromHandle(hScreenDC);
new CDC();
12: pSrcDC->CreateCompatibleDC(pScreenDC);
13: CBitmap* pSrcOldBitmap = pSrcDC->SelectObject(pSrcBitmap);
14:
15: pDestBitmap->CreateCompatibleBitmap(pSrcDC,destWidth,destHeight);
16:
new CDC();
18: pDestDC->CreateCompatibleDC(pSrcDC);
19: CBitmap* pDestOldBitmap = pDestDC->SelectObject(pDestBitmap);
20:
21: pDestDC->SetStretchBltMode(HALFTONE);
22: pDestDC->StretchBlt(0,0,destWidth,destHeight,pSrcDC,0,0,srcWidth,srcHeight,SRCCOPY);
23: pDestDC->SelectObject(pDestOldBitmap);
24: pSrcDC->SelectObject(pSrcOldBitmap);
25:
delete pDestDC;
delete pSrcDC;
28:
29: ::ReleaseDC(NULL,hScreenDC);
30: }
31:
//Save a bitmap as a bitmap file
//#include <atlimage.h>
new CBitmap();
35: pSrcBitmap->Attach(hBitmap);
36:
new CBitmap();
38: ScaleBitmap(pSrcBitmap,pDestBitmap,destWidth,destHeight);
39:
40: CImage image;
41: image.Attach((HBITMAP)*pDestBitmap);
42: image.Save(fileName, Gdiplus::ImageFormatBMP);
43: image.Detach();
44:
45: pSrcBitmap->Detach();
delete pSrcBitmap;
delete pDestBitmap;