circlesport

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

 1
 2        /// <summary>
 3        /// 生成缩略图
 4        /// </summary>
 5        /// <param name="oldpath">原图片地址</param>
 6        /// <param name="newpath">新图片地址</param>
 7        /// <param name="tWidth">缩略图的宽</param>
 8        /// <param name="tHeight">缩略图的高</param>

 9        private void  GreateMiniImage(string oldpath,string newpath,int tWidth, int tHeight)
10        {
11        
12            try
13            {
14
15                System.Drawing.Image image = System.Drawing.Image.FromFile(oldpath);
16                double bl=1d;
17                if((image.Width<=image.Height)&&(tWidth>=tHeight))
18                {
19                    bl=Convert.ToDouble(image.Height)/Convert.ToDouble(tHeight);
20                }

21                else if((image.Width>image.Height)&&(tWidth<tHeight))
22                {
23                    bl=Convert.ToDouble(image.Width)/Convert.ToDouble(tWidth);
24            
25                }

26                else
27            
28                    if((image.Width<=image.Height)&&(tWidth<=tHeight))
29                {
30                    if(image.Height/tHeight>=image.Width/tWidth)
31                    {
32                        bl=Convert.ToDouble(image.Width)/Convert.ToDouble(tWidth);
33                    
34                    }

35                    else
36                    {
37                        bl=Convert.ToDouble(image.Height)/Convert.ToDouble(tHeight);
38                    }

39                }

40                else
41                {
42                    if(image.Height/tHeight>=image.Width/tWidth)
43                    {
44                        bl=Convert.ToDouble(image.Height)/Convert.ToDouble(tHeight);
45                    
46                    }

47                    else
48                    {
49                        bl=Convert.ToDouble(image.Width)/Convert.ToDouble(tWidth);
50                    
51                    }

52            
53                }

54
55            
56                Bitmap b = new Bitmap(image ,Convert.ToInt32(image.Width/bl), Convert.ToInt32(image.Height/bl));
57
58                b.Save(newpath);
59                b.Dispose();
60                image.Dispose();
61                
62
63            }

64            catch
65            {
66            
67                
68            }

69            
70        }
posted on 2007-04-25 22:37  无极.net  阅读(652)  评论(4编辑  收藏  举报