cimage
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;
}
相关阅读
Visual C++的CBitmap类的功能是比较弱的,它只能显示出在资源中的图标、位图、光标以及图元文件的内容,而不像VB中的Image控件可以
其他关于此类的介绍:http://blog.csdn.net/wayaoqiang/article/details/7620745点击打开链接http://blog.sina.com.cn/s/blog_5a82
1.综述在MFC中CImageList类封装了图像列表控件的功能,图像列表是一个具有相同大小的图像(可以是不同类型)的集合,其主要用于应用程序