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

推荐订阅源

Martin Fowler
Martin Fowler
Jina AI
Jina AI
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
I
InfoQ
L
LangChain Blog
The Cloudflare Blog
IT之家
IT之家
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
博客园 - 聂微东
美团技术团队
博客园_首页

博客园 - 三聪

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

        }