C# 裁剪图片,从X,Y得到矩形?

C# 裁剪图片,从X,Y得到矩形?,c#,coordinates,points,C#,Coordinates,Points,我正试图从整数x,y坐标裁剪一张C格式的图片。。 我就是不知道怎么弄到它 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 R

我正试图从整数x,y坐标裁剪一张C格式的图片。。 我就是不知道怎么弄到它

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坐标,还要知道裁剪图像的宽度和高度。

这似乎是因为你还没有编写任何代码……什么是pointX,pointY?loword中x和hiword中y的压缩坐标?或者只是同一点的x和y,而0,0始终是另一个点?一个点不构成矩形。基本几何。看见
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;
}