CImage oldimg;
//加载图片
oldimg.Load(GetExePath() + "img\\" + "test.bmp");
if (oldimg.IsNull())
{
continue;
}
int oldWidth = oldimg.GetWidth();
int oldHeight = oldimg.GetHeight();
int newWidth = oldWidth+10;
int newHeight = oldHeight+10;
CImage newimg;
if (!newimg.CreateEx(newWidth, newHeight, 24, BI_RGB))
{
oldimg.Destroy();
continue;
}
//按比例放大或缩小图片
int nPreMode = ::SetStretchBltMode(newimg.GetDC(), HALFTONE);
newimg.ReleaseDC();
oldimg.Draw(newimg.GetDC(), 0, 0, newWidth, newHeight, 0, 0, oldWidth, oldHeight);
newimg.ReleaseDC();
::SetBrushOrgEx(newimg.GetDC(), 0, 0, NULL);
newimg.ReleaseDC();
::SetStretchBltMode(newimg.GetDC(), nPreMode);
newimg.ReleaseDC();
//裁剪图片
int cutWidth = oldWidth/2;
int cutHeight = oldHeight/2;
CImage timg;
timg.Create(cutWidth, cutHeight, oldimg.GetBPP());
oldimg.BitBlt(timg.GetDC(), 0, 0, cutWidth, cutHeight, 0, 0, SRCCOPY);
timg.TransparentBlt(pDC->GetSafeHdc(), 0, 0, cutWidth, cutHeight, RGB(255, 255, 255));
timg.ReleaseDC();
timg.Destroy();
newimg.Destroy();
oldimg.Destroy();
CImage缩放图片、截图图片
最新推荐文章于 2025-05-29 15:47:03 发布