大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 如何等比例缩放图像

如何等比例缩放图像

时间: 2021-07-31 作者:daque

作家:徐景周在夸大或减少图像时,怎样能最佳的维持图像原态比率来表露呢?底下供给一个涵数可帮你来实行,挪用它后,归来的矩形地区既为最好表露图像巨细。l         涵数中的第一个参数rcscreen为图像要被表露的矩形巨细,第二个参数sizepicture为图像自己巨细,第三个参数bcenter为能否居中表露,归来值crect既为图像最好表露巨细。涵数如次所示:crect rectsizewithconstantratio( crect* rcscreen,                                       csize sizepicture,                                       bool bcenter){  crect rect(rcscreen);  double dwidth = rcscreen->width();  double dheight = rcscreen->height();  double daspectratio = dwidth/dheight;  double dpicturewidth = sizepicture.cx;  double dpictureheight = sizepicture.cy;  double dpictureaspectratio = dpicturewidth/dpictureheight;  //if the aspect ratios are the same then the screen rectangle  // will do, otherwise we need to calculate the new rectangle  if (dpictureaspectratio > daspectratio)  {    int nnewheight = (int)(dwidth/dpicturewidth*dpictureheight);    int ncenteringfactor = (rcscreen->height() - nnewheight) / 2;    rect.setrect( 0,                  ncenteringfactor,                  (int)dwidth,                  nnewheight + ncenteringfactor);  }  else if (dpictureaspectratio < daspectratio)  {    int nnewwidth =  (int)(dheight/dpictureheight*dpicturewidth);    int ncenteringfactor = (rcscreen->width() - nnewwidth) / 2;    rect.setrect( ncenteringfactor,                   0,                  nnewwidth + ncenteringfactor,                  (int)(dheight));  }  return rect;};接洽办法:email:jingzhou_xu@163.net将来处事室(future studio)

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.