×÷ÕߣºÐì¾°ÖÜ
ÔÚ·Å´ó»òËõСͼÏñʱ£¬ÈçºÎÄÜ×îºÃµÄ±£³ÖͼÏñÔ̬±ÈÀýÀ´ÏÔÊ¾ÄØ£¿ÏÂÃæÌṩһ¸öºÊý¿É°ïÄãÀ´ÊµÏÖ£¬µ÷ÓÃËüºó£¬·µ»ØµÄ¾ØÐÎÇøÓò¼ÈΪ×î¼ÑÏÔʾͼÏñ´óС¡£
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£º[email protected]
δÀ´¹¤×÷ÊÒ(Future Studio)
±¾ÎĵØÖ·£ºhttp://com.8s8s.com/it/it2786.htm