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

推荐订阅源

博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
博客园 - Franky
IT之家
IT之家
V
Visual Studio Blog
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
博客园 - 叶小钗
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
罗磊的独立博客
小众软件
小众软件
Jina AI
Jina AI

博客园 - 三聪

流操作 如何利用.Net内置类,解析未知复杂Json对象 让window.setTimeout等支持带参数方法 利用NewID()生成随机数 创建缩略图 winform给html提供接口 IE下记住文本框的光标位置 ie下取得iframe里面内容 短网址计算 树冲突 截图片 学习Objective-C: 入门教程 C#根据字节数截取字符串 asp.net本地和全局资料文件的读取方法 jquery实现点击空白的事件 Asp.net 利用Jquery Ajax传送和接收DataTable 用一个最简单方法解决asp.net页面刷新导致数据的重复提交 SOS"未将对象引用设置到对象的实例" .NET调PHP Web Service的典型例子
制作等比环切缩缩图
三聪 · 2013-03-01 · via 博客园 - 三聪
 /// <summary>
    /// 制作等比环切缩缩图
    /// </summary>

    public static bool MakeThumbnail(Image image, string savePath, int toWidth, int toHeight)
    {
        if (File.Exists(savePath))
        {
            File.SetAttributes(savePath, FileAttributes.Normal);
            File.Delete(savePath);
        }

        if (image == null) return false;

        int x = 0;
        int y = 0;
        int ow = image.Width;
        int oh = image.Height;

        if ((double)image.Width / image.Height > (double)toWidth / toHeight)
        {
            oh = image.Height;
            ow = image.Height * toWidth / toHeight;
            x = (image.Width - ow) / 2;
        }
        else
        {
            ow = image.Width;
            oh = image.Width * toHeight / toWidth;
            y = (image.Height - oh) / 2;
        }

        Bitmap bmPhoto = new Bitmap(toWidth, toHeight, PixelFormat.Format24bppRgb);
        Graphics gbmPhoto = Graphics.FromImage(bmPhoto);
        gbmPhoto.InterpolationMode = InterpolationMode.High;
        gbmPhoto.SmoothingMode = SmoothingMode.HighQuality;
        gbmPhoto.Clear(Color.White);
        gbmPhoto.DrawImage(image, new Rectangle(0, 0, toWidth, toHeight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);

        ImageCodecInfo myImageCodecInfo;
        Encoder myEncoder;
        EncoderParameter myEncoderParameter;
        EncoderParameters myEncoderParameters;

        myImageCodecInfo = GetEncoderInfo("image/jpeg");
        myEncoder = Encoder.Quality;
        myEncoderParameters = new EncoderParameters(1);
        myEncoderParameter = new EncoderParameter(myEncoder, 99L);
        myEncoderParameters.Param[0] = myEncoderParameter;
        bmPhoto.Save(savePath, myImageCodecInfo, myEncoderParameters);

        gbmPhoto.Dispose();
        bmPhoto.Dispose();
        return true;
    }