//缩放函数
// Resize CImage
void CreateStretchImage(CImage *pImage,CImage *ResultImage,int StretchHeight,int StretchWidth)
{
if(pImage->IsDIBSection())
{
// 取得 pImage 的 DC
CDC* pImageDC1 = CDC::FromHandle(pImage->GetDC()); // Image 因為有自己的 DC, 所以必須使用 FromHandle 取得對應的 DC
CBitmap *bitmap1=pImageDC1->GetCurrentBitmap();
BITMAP bmpInfo;
bitmap1->GetBitmap(&bmpInfo);
// 建立新的 CImage
ResultImage->Create(StretchWidth,StretchHeight,bmpInfo.bmBitsPixel);
CDC* ResultImageDC = CDC::FromHandle(ResultImage->GetDC());
// 當 Destination 比較小的時候, 會根據 Destination DC 上的 Stretch Blt mode 決定是否要保留被刪除點的資訊
ResultImageDC->SetStretchBltMode(HALFTONE); // 使用最高品質的方式
::SetBrushOrgEx(ResultImageDC->m_hDC,0,0,NULL); // 調整 Brush 的起點
// 把 pImage 畫到 ResultImage 上面
StretchBlt(*ResultImageDC,0,0,StretchWidth,StretchHeight,*pImageDC1,0,0,pImage->GetWidth(),pImage->GetHeight(),SRCCOPY);
// pImage->Draw(*ResultImageDC,0,0,StretchWidth,StretchHeight,0,0,pImage->GetWidth(),pImage->GetHeight());
pImage->ReleaseDC();
ResultImage->ReleaseDC();
}
}
//调用方式
//m_strFile 文件路径
CImage wImg,sImg;
wImg.Load(m_strFile);
CreateStretchImage(&wImg,&sImg,wImg.GetHeight()/3,wImg.GetWidth()/3);
sImg.Save(_T("c:\\wxp.bmp"));