图片的修改(上传图片时,做的缩小或放大操作)

作者:互联网   出处:控件中国网   2014-11-05 19:05:13   阅读:1

图片的修改(上传图片时,做的缩小或放大操作)
 
 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         }
 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat