如何使用 C# 裁剪图像? [英] How to crop an image using C#?
本文介绍了如何使用 C# 裁剪图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能用 C# 编写一个裁剪图像的应用程序?
How can I write an application that will crop images in C#?
推荐答案
您可以使用 Graphics.DrawImage
从位图中将裁剪图像绘制到图形对象上.
You can use Graphics.DrawImage
to draw a cropped image onto the graphics object from a bitmap.
Rectangle cropRect = new Rectangle(...);
Bitmap src = Image.FromFile(fileName) as Bitmap;
Bitmap target = new Bitmap(cropRect.Width, cropRect.Height);
using(Graphics g = Graphics.FromImage(target))
{
g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height),
cropRect,
GraphicsUnit.Pixel);
}
这篇关于如何使用 C# 裁剪图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文