//Draw picture.
{
int iWidth = m_pBitmap->GetWidth();
int iHeight = m_pBitmap->GetHeight();
CRect rct(0, 0, iWidth, iHeight);
if ((float)rct.Width() / (float)rct.Height() > (float)m_rctClient.Width() / (float)m_rctClient.Height())
{
iWidth = (int)((float)iHeight * (float) m_rctClient.Width() / (float)m_rctClient.Height());
int iMargin = (rct.Width() - iWidth) / 2;
rct.left += iMargin;
rct.right -= iMargin;
}
if ((float)rct.Width() / (float)rct.Height() < (float)m_rctClient.Width() / (float)m_rctClient.Height())
{
iHeight = (int)((float)iWidth * (float)m_rctClient.Height() / (float)m_rctClient.Width());
int iMargin = (rct.Height() - iHeight) / 2;
rct.top += iMargin;
rct.bottom -= iMargin;
}
pRT->DrawBitmap(m_pBitmap, GetRect_2(m_rctClient), GetRect_2(rct), 1.0F, FALSE);
}
本文介绍了一种算法,用于根据客户端窗口的尺寸调整图片大小,确保图片在不同设备上都能完美显示。通过计算图片宽度与高度的比例,与客户端窗口的比例进行比较,算法能够智能地调整图片尺寸,同时保持其原始比例。这种方法适用于网页开发中,特别是在响应式设计中,以优化用户体验。
3420

被折叠的 条评论
为什么被折叠?



