zoukankan      html  css  js  c++  java
  • 图片的修改(上传图片时,做的缩小或放大操作)

    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 }
  • 相关阅读:
    Web基础 网页的血肉CSS
    18
    19
    20
    17
    16
    15
    13
    14
    12
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2049432.html
Copyright © 2011-2022 走看看