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

推荐订阅源

量子位
F
Fortinet All Blogs
小众软件
小众软件
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
有赞技术团队
有赞技术团队
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
A
About on SuperTechFans
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
罗磊的独立博客
C
Check Point Blog
大猫的无限游戏
大猫的无限游戏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog

博客园 - 三聪

流操作 如何利用.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的典型例子
截图片
三聪 · 2011-03-16 · via 博客园 - 三聪

 public static Image CutImage(Image img, int width, int height)
        {
            Bitmap image 
= new Bitmap(img);int calheight = width * image.Height / image.Width;
            
int calwidth = height * image.Width / image.Height;

            Image img2;

if (calheight >= height)
            {
                img2 
= image.GetThumbnailImage(width, calheight, null, IntPtr.Zero);
            }
            
else
            {
                img2 
= image.GetThumbnailImage(calwidth, height, null, IntPtr.Zero);
            }

            Bitmap bitmap 

= new Bitmap(img2);
            
int x = (bitmap.Width - width) / 2;
            
int y = (bitmap.Height - height) / 2;
            Rectangle cloneRect 
= new Rectangle(x, y, width, height);
            PixelFormat format 
= bitmap.PixelFormat;
            Bitmap cloneBitmap 
= bitmap.Clone(cloneRect, format);return cloneBitmap;

        }