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

推荐订阅源

Help Net Security
Help Net Security
Recent Announcements
Recent Announcements
A
About on SuperTechFans
N
News and Events Feed by Topic
I
Intezer
B
Blog
GbyAI
GbyAI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
T
Troy Hunt's Blog
TaoSecurity Blog
TaoSecurity Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
The Register - Security
The Register - Security
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
P
Privacy & Cybersecurity Law Blog
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Hacker News - Newest:
Hacker News - Newest: "LLM"
G
Google Developers Blog
罗磊的独立博客
博客园 - 聂微东
G
GRAHAM CLULEY
AWS News Blog
AWS News Blog
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
C
Check Point Blog
L
Lohrmann on Cybersecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy
O
OpenAI News
T
Tor Project blog
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 最新话题
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
S
Securelist
博客园_首页

博客园 - 三聪

流操作 如何利用.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;
    }