大家好,又见面了,我是你们的朋友全栈君。
bool ResizePicture(CString strSource, CString strTarget)
{
int WIDTH = 70;
int HEIGHT = 70;
CImage oldimg;
CImage newimg;
oldimg.Load(strSource);
if (oldimg.IsNull())
return false;
int nWidth = 0;
int nHeight = 0;
nWidth = oldimg.GetWidth();
nHeight = oldimg.GetHeight();
if (nWidth > WIDTH || nHeight > HEIGHT)
{
double dRatio = nWidth * 1.0 / nHeight;
if (nWidth > nHeight)
{
nWidth = WIDTH;
nHeight = (int)(nWidth / dRatio);
}
else
{
nHeight = HEIGHT;
nWidth = (int)(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(strTarget);
newimg.Destroy();
oldimg.Destroy();
return true;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/149152.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...