-
在VS2015 C++ MFC中实现图片等比例缩小分辨率尺寸
资源介绍
VS2015 C++ MFC 等比缩小图片分辨率大小
bool CtestCImageDlg::CreateSmallPic(CString& szOldFileName, CString& szNewFilName)
{
const double WIDTH = 5000;
const double HEIGHT = 5000;
CImage oldimg;
CImage newimg;
oldimg.Load(szOldFileName);
if (oldimg.IsNull())
return false;
int nWidth = 160;
int nHeight = 160;
nWidth = oldimg.GetWidth();
nHeight = oldimg.GetHeight();
if (nWidth > WIDTH || nHeight > HEIGHT)
{
double dRatio = nWidth * 1.0 / nHeight;
if (nWidth > nHeight)
{
nWidth = WIDTH;
nHeight = nWidth / dRatio;
}
else
{
nHeight = HEIGHT;
nWidth = nHeight * dRatio;
}
}
if (!newimg.CreateEx(nWidth, nHeight, 24, BI_RGB))
{
oldimg.Destroy();
return false;
}
int nPreMode = ::SetStretchBltMode(newimg.GetDC(), HALFTONE);
newimg.ReleaseDC();
oldimg.Draw(newimg.GetDC(), 0, 0, nWidth, nHeight, 0, 0, oldimg.GetWidth(), oldimg.GetHeight());
newimg.ReleaseDC();
::SetBrushOrgEx(newimg.GetDC(), 0, 0, NULL);
newimg.ReleaseDC();
::SetStretchBltMode(newimg.GetDC(), nPreMode);
newimg.ReleaseDC();
newimg.Save(szNewFilName);
newimg.Destroy();
oldimg.Destroy();
return true;
}
- 上一篇: PictureBox实现拖拽操作
- 下一篇: c++编写函数实现图片缩小放大