惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
D
DataBreaches.Net
腾讯CDC
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
月光博客
月光博客
MyScale Blog
MyScale Blog
U
Unit 42
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园 - 【当耐特】
D
Docker
I
InfoQ
雷峰网
雷峰网

博客园 - Rickel

在webView 中使用JS 调用 Android / IOS的函数 Function 数据库镜像的配置 查看SQL Server中某数据库下每个表占用的空间大小 about WBS sql server 2005 压缩实例下所有数据库文件及日志文件 语句 TFS服务器及服务帐号迁域的处理 [西安招聘] 微软西安分公司 招聘.NET软件工程师,MOSS开发工程师 SQL清除数据库日志方法 JavaScript 中的Key 事件区别 ASP.NET URL Rewrite. URL重写 Apache Error:(OS 10048)Only one usage of each socket address is normally permitted. 页面响应自定义控件的事件 推荐大家看 《亵渎》 断字处理 break-word I'm Back 部署带Crystal Reports的Web应用程序 用C#读取Excel文件:从指定单元格开始向右向下读取数据 Well-formed AssemblyInfo.cs 毕业一周年纪念
生成高品质的缩略图
Rickel · 2007-02-04 · via 博客园 - Rickel

转自:http://hi.baidu.com/zhaoyf/blog/item/06d6b812175371cec2fd7812.html

高品质,就是指定Graphic的

InterpolationMode属性为HighQualityBicubic

public static void myGetThumbnailImage(string SourceFile, string strSavePathFile, int ThumbWidth, int ThumbHeight, string BgColor) 
    { 
        System.Drawing.Image oImg 
= System.Drawing.Image.FromFile(SourceFile); 
        
//小图 
        int intwidth, intheight; 
        
if (oImg.Width > oImg.Height) 
        { 
            
if (oImg.Width > ThumbWidth) 
            { 
                intwidth 
= ThumbWidth; 
                intheight 
= (oImg.Height * ThumbWidth) / oImg.Width; 
            } 
            
else 
            { 
                intwidth 
= oImg.Width; 
                intheight 
= oImg.Height; 
            } 
        } 
        
else 
        { 
            
if (oImg.Height > ThumbHeight) 
            { 
                intwidth 
= (oImg.Width * ThumbHeight) / oImg.Height; 
                intheight 
= ThumbHeight; 
            } 
            
else 
            { 
                intwidth 
= oImg.Width; 
                intheight 
= oImg.Height; 
            } 
        } 
        
//构造一个指定宽高的Bitmap 
        Bitmap bitmay = new Bitmap(intwidth, intheight); 
        Graphics g 
= Graphics.FromImage(bitmay); 
        Color myColor; 
        
if (BgColor == null
            myColor 
= Color.FromName("white"); 
        
else 
            myColor 
= Color.FromName(BgColor); 
        
//用指定的颜色填充Bitmap 
        g.Clear(myColor); 
        g.InterpolationMode 
= InterpolationMode.HighQualityBicubic;  
        
//开始画图 
        g.DrawImage(oImg, new Rectangle(00, intwidth, intheight), new Rectangle(00, oImg.Width, oImg.Height), GraphicsUnit.Pixel); 
        bitmay.Save(strSavePathFile, System.Drawing.Imaging.ImageFormat.Jpeg); 
        g.Dispose(); 
        bitmay.Dispose(); 
        oImg.Dispose(); 
        
//删除源图 
        try 
        { 
            File.Delete(SourceFile); 
        } 
        
catch 
        { 
        } 
    }