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

推荐订阅源

C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
WordPress大学
WordPress大学
月光博客
月光博客
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - 司徒正美
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
Blog — PlanetScale
Blog — PlanetScale
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
L
LangChain Blog
腾讯CDC
T
The Blog of Author Tim Ferriss
量子位

博客园 - 金大侠

基于Extjs web设计器 Sqlserver 差异备份 DataTable使用方法总结 大话prototype Js生成组织结构图 关于读取windows域的用户最后登录时间 经典javascript 一行文字显示不了,用...替代解决方案 .net 发送邮件 将word转换成其它文件 数据挖掘 Web 控件库 SQL Server 2005 在MDX中的新特性 客户端访问WebService Smart Client 解决导出Excel格式问题 泛型学习 asp.net优化方案 windows2008 IIS7.0使用手记 图片推理1
.net生成略缩图
金大侠 · 2009-07-02 · via 博客园 - 金大侠

/// <summary>
    /// 生成略缩图
    /// </summary>
    /// <param name="fileName">源文件路径</param>
    /// <param name="newFile">新文件路径</param>
    /// <param name="maxWidth">生成新文件的宽度,高度自动算</param>
    public static void SendSmallImage(string fileName, string newFile, int maxWidth)
    {
        System.Drawing.Image img = System.Drawing.Image.FromFile(fileName);
        System.Drawing.Imaging.ImageFormat
        thisFormat = img.RawFormat;
        int maxHeight = img.Height * maxWidth / img.Width;
        Size newSize = NewSize(maxWidth, maxHeight, img.Width, img.Height);
        Bitmap outBmp = new Bitmap(newSize.Width, newSize.Height);
        Graphics g = Graphics.FromImage(outBmp);        // 设置画布的描绘质量
        g.DrawImage(img, new System.Drawing.Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
        g.Dispose();
        // 以下代码为保存图片时,设置压缩质量
        EncoderParameters encoderParams = new EncoderParameters();
        long[] quality = new long[1];
        quality[0] = 100;
        EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
        encoderParams.Param[0] = encoderParam;
        //获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象.
        ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
        ImageCodecInfo jpegICI = null;
        for (int x = 0; x < arrayICI.Length; x++)
        {
            if (arrayICI[x].FormatDescription.Equals("JPEG"))
            {
                jpegICI = arrayICI[x];
                //设置JPEG编码
                break;
            }
        }
        if (jpegICI != null)
        {
            outBmp.Save(newFile, jpegICI, encoderParams);
        }
        else
        {
            outBmp.Save(newFile,
            thisFormat);
        }
        img.Dispose();
        outBmp.Dispose();
    }

posted on 2009-07-02 09:03  金大侠  阅读(299)  评论()    收藏  举报