2024年4月12日发(作者:)

// 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,Pixel);

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,pI

mage->GetWidth(),pImage->GetHeight(),SRCCOPY);

//

pImage->Draw(*ResultImageDC,0,0,StretchWidth,StretchHeight,0,0,pImage->Get

Width(),pImage->GetHeight());

pImage->ReleaseDC();

ResultImage->ReleaseDC();

}

}

// 建立指定大小的圖形

// 輸入: 原始圖檔=pBitmap, 指定大小=StretchHeight StretchWidth, 結果圖檔

=pResultBmp