zoukankan      html  css  js  c++  java
  • C#生成高清缩略图

    01 /// <summary> 
    02    /// 为图片生成缩略图   
    03    /// </summary> 
    04    /// <param name="phyPath">原图片的路径</param> 
    05    /// <param name="width">缩略图宽</param> 
    06    /// <param name="height">缩略图高</param> 
    07    /// <returns></returns> 
    08    public System.Drawing.Image GetThumbnail(System.Drawing.Image image, int width, intheight) 
    09    
    10        Bitmap bmp = newBitmap(width, height); 
    11        //从Bitmap创建一个System.Drawing.Graphics 
    12        System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); 
    13        //设置  
    14        gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
    15        //下面这个也设成高质量 
    16        gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; 
    17        //下面这个设成High 
    18        gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
    19        //把原始图像绘制成上面所设置宽高的缩小图 
    20        System.Drawing.Rectangle rectDestination = newSystem.Drawing.Rectangle(0, 0, width, height); 
    21     
    22        gr.DrawImage(image, rectDestination, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); 
    23        returnbmp; 
    24    }

    调用方法

    01 HttpPostedFile file = photoFile.PostedFile; 
    02         if(!file.ContentType.Contains("image")) 
    03         
    04 return"照片格式不合法"
    05         
    06         stringext = Path.GetExtension(file.FileName).ToLower(); 
    07         if (ext != ".jpg" && ext != ".gif" && ext != ".png"&& ext != ".jpeg"
    08         
    09 return"请您上传jpg、gif、png图片"
    10         
    11         if(file.ContentLength > 5 * 1024 * 1024) 
    12         
    13 return"请您上传512字节内的图片"
    14         
    15         stringnewName = Guid.NewGuid().ToString(); 
    16         stringtempPath = "upload/"
    17         stringimg = tempPath + newName + ext; 
    18         stringfilePath = Server.MapPath(img); 
    19         if(!Directory.Exists(tempPath)) 
    20         
    21             Directory.CreateDirectory(tempPath); 
    22         
    23         using(System.Drawing.Image originalImage = System.Drawing.Image.FromStream(file.InputStream)) 
    24         
    25             GetThumbnail(originalImage, 504, 374).Save(filePath); 
    26         }
  • 相关阅读:
    windows下python-nmap运行过程中出现的问题及解决办法
    命令行下cl.exe编译链接的问题及解决方法
    httrack: error while loading shared libraries: libhttrack.so.2的解决方法
    AES加解密非固定长度文本的用法
    John the Ripper password cracker试用
    ubuntu12.04使用root登陆的简单设置
    map按value查找相应元素
    ListCtrl添加右键菜单(ListCtrl类里编辑,给ListCtrl 发送NM_RCLICK消息)
    今天发现里一个非常好用的Listbox自绘类,带不同文字字体和图片,觉得很有必要记下来
    自绘listCtrl控件选中该行高亮(模拟windows)
  • 原文地址:https://www.cnblogs.com/gc2013/p/3652469.html
Copyright © 2011-2022 走看看