如何削减形象在C#中的一部分 [英] How to cut a part of image in C#
本文介绍了如何削减形象在C#中的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何削减从其他大图像的矩形图像。
假设有 300×600 image.png。的
我只想切断与一个长方形的的 X:10Ÿ20,200,高度100 的并保存为其他文件
I want just to cut a rectangle with X: 10 Y 20 , with 200, height 100 and save it into other file.
我如何在C#中做呢?
谢谢!
推荐答案
检查出的图形类的MSDN上。
Check out the Graphics Class on MSDN.
下面是一个例子,这将指向您在正确的方向(注意矩形
)对象:
Here's an example that will point you in the right direction (notice the Rectangle
object):
public Bitmap CropImage(Bitmap source, Rectangle section)
{
// An empty bitmap which will hold the cropped image
Bitmap bmp = new Bitmap(section.Width, section.Height);
Graphics g = Graphics.FromImage(bmp);
// Draw the given area (section) of the source image
// at location 0,0 on the empty bitmap (bmp)
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
return bmp;
}
// Example use:
Bitmap source = new Bitmap(@"C:\tulips.jpg");
Rectangle section = new Rectangle(new Point(12, 50), new Size(150, 150));
Bitmap CroppedImage = CropImage(source, section);
这篇关于如何削减形象在C#中的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文