工作中点滴记录

永远保持学徒心态

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
View Code
1 string sFileName = Path.GetFileNameWithoutExtension(this.FileUpload1.FileName);
2 string sExtension = Path.GetExtension(FileUpload1.FileName);
3 double size = FileUpload1.PostedFile.ContentLength / 1024;
4 if (size < 60)
5 {
6 string fi = Server.MapPath(@"img/") + sFileName + sExtension;
7 if (sExtension == ".gif" || sExtension == ".jpg" || sExtension == ".bmp" || sExtension == ".png")
8 {
9 System.Drawing.Image image = System.Drawing.Image.FromStream(this.FileUpload1.PostedFile.InputStream);
10 int width = image.Width;
11 int height = image.Height;
12 int max = 40;
13 try
14 {
15 System.Drawing.Image newPic;
16 if (width > height)
17 {
18 newPic = new System.Drawing.Bitmap(image, max, height * max / width);
19 }
20 else
21 {
22 newPic = new System.Drawing.Bitmap(image, width * max / height, max);
23 }
24 newPic.Save(fi, System.Drawing.Imaging.ImageFormat.Jpeg);
25 img1.Src = @"img\" + sFileName + sExtension;
26 }
27 catch (Exception ex)
28 {
29
30 }
31 }
32 }
posted on 2011-05-17 23:14  梦里故乡  阅读(530)  评论(2编辑  收藏  举报