public static Size ProportionalSize(Size imageSize, Size MaxW_MaxH)
{
double multBy= 1.01;
double w= imageSize.Width; double h= imageSize.Height;
while(w < MaxW_MaxH.Width && h < MaxW_MaxH.Height)
{
w= imageSize.Width*multBy;
h= imageSize.Height*multBy;
multBy= multBy+.001;
}
while(w > MaxW_MaxH.Width || h > MaxW_MaxH.Height)
{
multBy= multBy-.001;
w= imageSize.Width*multBy;
h= imageSize.Height*multBy;
}
if(imageSize.Width < 1)
imageSize=new Size(imageSize.Width+-imageSize.Width+1, imageSize.Height-imageSize.Width-1);
if(imageSize.Height < 1)
imageSize=new Size(imageSize.Width-imageSize.Height-1, imageSize.Height+-imageSize.Height+1);
imageSize= new Size(Convert.ToInt32(w), Convert.ToInt32(h));
return imageSize;
}