按比例缩放图片,C#代码,在实际的图片处理或网页上传程序中,我想这个比较实用,希望对大家有用,费话少说,看代码:
01private static Size NewSize(int maxWidth, int maxHeight, int width, int height)
02{
03 double w = 0.0;
04 double h = 0.0;
05 double sw = Convert.ToDouble(width);
06 double sh = Convert.ToDouble(height);
07 double mw = Convert.ToDouble(maxWidth);
08 double mh = Convert.ToDouble(maxHeight);
09 if (sw < mw && sh < mh)
10 {
11 w = sw;
12 h = sh;
13 }
14 else if ((sw / sh) > (mw / mh))
15 {
16 w = maxWidth;
17 h = (w * sh) / sw;
18 }
19 else
20 {
21 h = maxHeight;
22 w = (h * sw) / sh;
23 }
24 return new Size(Convert.ToInt32(w), Convert.ToInt32(h));
25}
从书中学来的,懂C#的应该知道怎么用。
更多信息请查看IT技术专栏