posts - 43,  comments - 117,  trackbacks - 12
使用C# 生成缩略图,可以进行修改,以实现需要的功能,如图片大小等
 1/// <summary>
 2        /// 生成缩略图
 3        /// </summary>
 4        /// <param name="ImagePath">大图路径</param>
 5        /// <param name="SavPath">缩略图保持路径</param>
 6        /// <param name="extention">图片后缀</param>
 7        /// <param name="ID">图片ID</param>

 8        public void BreviaryImage(string ImagePath,string SavPath,string extention ,int ID)
 9        {
10            using(System.Drawing.Image image = System.Drawing.Image.FromFile(strPath + ImagePath + ID + extention))
11            {
12                decimal width = image.Width;
13                decimal height = image.Height;
14                int newwidth,newheight;
15            
16                if(width>height)
17                {
18                    newwidth=100;
19                    newheight=(int)(height/width*100);
20                }

21                else
22                {
23                    newheight=100;
24                    newwidth=(int)(width/height*100);
25                }

26            
27                string FilePath=strPath+SavPath;
28                if (!Directory.Exists(FilePath))
29                    Directory.CreateDirectory(FilePath);
30
31                using(System.Drawing.Image aNewImage=image.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero))
32                {
33                    aNewImage.Save(FilePath + ID + extention);
34                }

35            }

36        }
posted on 2006-10-31 12:14 空空儿 阅读(219) 评论(0)  编辑 收藏 网摘 所属分类: C#