图片的修改(上传图片时,做的缩小或放大操作)
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 }
图片的修改(上传图片时,做的缩小或放大操作)
热推产品
- ActiveReport... 强大的.NET报表设计、浏览、打印、转换控件,可以同时用于WindowsForms谀坔攀戀Forms平台下......
- AnyChart AnyChart使你可以创建出绚丽的交互式的Flash和HTML5的图表和仪表控件。可以用于仪表盘的创......
推荐产品