Public struct picsize
{
Public int width;
Public int height;
}
Public static picsize adjustsize (INT spcwidth, int spcheight, int orgwidth, int orgheight)
{
Picsize size = new picsize ();
// The original width and height are within the specified width and height range and are not processed.
If (orgwidth <= spcwidth & orgheight <= spcheight)
{
Size. width = orgwidth;
Size. Height = orgheight;
}
Else
{
// Obtain the proportional coefficient
Float W = orgwidth/(float) spcwidth;
Float H = orgheight/(float) spcheight;
// The width ratio is greater than the height ratio.
If (W> H)
{
Size. width = spcwidth;
Size. Height = (INT) (W> = 1? Math. Round (orgheight/W): Math. Round (orgheight * w ));
}
// The width ratio is smaller than the height ratio.
Else if (W {
Size. Height = spcheight;
Size. width = (INT) (H> = 1? Math. Round (orgwidth/h): Math. Round (orgwidth * H ));
}
// Ratio of width to height
Else
{
Size. width = spcwidth;
Size. Height = spcheight;
}
}
Return size;
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/hanghwp/archive/2009/09/04/4517401.aspx