图像缩放和居中显示的问题
flmn 2003-05-01 11:05:35 一个MDI子窗体中,上面放一个TImage,动态载入图片
我想让载入的图像缩放正好显示,如果图片的长和宽都小于MDI主窗体(FormMain)的长和宽,就按原来大小显示,如果不满足以上条件,就缩放,显示的图像尽量大,最后让这个子窗体显示在主窗体的中间。源码如下:
if (Image->Picture->Width < FormMain->ClientWidth - 55
&& Image->Picture->Height < FormMain->ClientHeight - 55) {
int picWidth = Image->Picture->Width;
int picHeight = Image->Picture->Height;
Image->Width = picWidth;
Image->Height = picHeight;
ClientWidth = picWidth;
ClientHeight = picHeight;
} else if (Image->Picture->Width > Image->Picture->Height) {
Image->Width = FormMain->ClientWidth - 50;
ClientWidth = Image->Width;
Image->Height = Image->Picture->Height* ClientHeight/Image->Picture->Width;
} else {
Image->Height = FormMain->ClientHeight - 50;
ClientHeight = Image->Height;
Image->Width = Image->Picture->Width * ClientWidth / Image->Picture->Height;
}
Left = (FormMain->ClientWidth - Width) / 2;
Top = (FormMain->ClientHeight - Height) / 2;
现在的问题是,如果图片的长或宽有一个大于MDI主窗体(FormMain)的长或宽 ,显示出来的图片旁边有很大空白,我不明白,请高手给我看看。
Image的几个属性:
autosize=false
Stretch = true
Proportional=true