19,468
社区成员
发帖
与我相关
我的任务
分享
//****************************************************************************************//
//函数 CKBaseObj::CreateSmallPic
//主要功能: 将一个大图转成小图
//参数列表:
// 1、char *szOldFileName:
// 2、char *szNewFilName:
//返回值:
//备注: 对于小图片不转
//****************************************************************************************//
bool CKBaseObj::CreateSmallPic(char *szOldFileName, char *szNewFilName)
{
const WIDTH = 160;
const HEIGHT = 160;
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;
}