时间: 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)