裁剪图片,从X,Y获取矩形? [英] Cropping picture, getting Rectangle from X,Y?
本文介绍了裁剪图片,从X,Y获取矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从C,C的整数x,y坐标中裁剪图片。
我只是不知道该如何获取图片?
I'm trying to crop a picture in C# from integer x, y coordinates.. I just can't figure out how to get it?
public void doCroppedImage(int pointX, int pointY)
{
Rectangle cropRect = //???
}
推荐答案
您可以使用此代码。
public static Bitmap CropImage(Image source, int x,int y,int width,int height)
{
Rectangle crop = new Rectangle(x, y, width, height);
var bmp = new Bitmap(crop.Width, crop.Height);
using (var gr = Graphics.FromImage(bmp))
{
gr.DrawImage(source, new Rectangle(0, 0, bmp.Width, bmp.Height), crop, GraphicsUnit.Pixel);
}
return bmp;
}
但是要评论一个图像,您不仅要知道x和裁切点的y坐标,以及裁切后图像的宽度和高度。
But one comment, to crop an image you have to know not only the x and y coordinates of cropping point but also the width and height of the cropped image.
这篇关于裁剪图片,从X,Y获取矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文