登录 注册
当前位置:主页 > 资源下载 > 41 > 在VS2015 C++ MFC中实现图片等比例缩小分辨率尺寸

在VS2015 C++ MFC中实现图片等比例缩小分辨率尺寸

  • 更新:2024-09-05 17:06:08
  • 大小:60KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C++ - 后端
  • 格式:7Z

资源介绍

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; }