实现AcdSee的缩略图功能 很多图片以缩略图方式显示,可以控制图片显示大小,如何做才能比较快的显示,而且资源要求不要太多。分不是问题,搞定再加! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在放大或缩小图像时,如何能最好的保持图像原态比例来显示呢?下面提供一个涵数可帮你来实现,调用它后,返回的矩形区域既为最佳显示图像大小。 涵数中的第一个参数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 rectangleif (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;}; 此涵数的使用方法如下:{……(部分省略)//得到屏幕大小CRect rcScreen( 0, 0, GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));//得到图像尺寸CSize sizePicture(picture.m_Width, picture.m_Height); CRect rcNewPictureRect = SizeRectWithConstantAspectRatio(&rcScreen,sizePicture,TRUE);picture.Show(&dc, rcNewPictureRect);} 求助VC++编程 学习OLE DB前需要研究COM吗? 请教高手windows程序设计基础 程序运行一段时间,反应越来越慢,怀疑绘图程序有内存泄露,请问这段程序有什么问题么? 300分求教(另开贴增分):如何编程实现控制一个文件夹的访问? Sqlite如何自动更新时间字段。 请大家帮我分析一下 有谁用过CFileFind类,为什么我会有这样的问题 如何实现类似sqlserver中的SCHEDUL TASK的功能? TreeView选中项问题 如何保存线程的指针? 怎样将CListView中的ListCtrl声明成CListCtrl 的派生类?
涵数中的第一个参数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 rectangleif (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;
};
 此涵数的使用方法如下:
{
……(部分省略)
//得到屏幕大小
CRect rcScreen( 0, 0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN));//得到图像尺寸
CSize sizePicture(picture.m_Width, picture.m_Height); CRect rcNewPictureRect =
SizeRectWithConstantAspectRatio(&rcScreen,
sizePicture,
TRUE);
picture.Show(&dc, rcNewPictureRect);
}