裁剪带有顶部和底部边距的图像

crop image with a margin top and bottom

我有一张图片

我必须裁剪 "margin" 顶部和底部。我写了这段代码,但只适用于 top margin

public static Bitmap Crop(Image myImage)
{
    Bitmap croppedBitmap = new Bitmap(myImage);
    croppedBitmap = croppedBitmap.Clone(
                    new Rectangle(100,100,myImage.Width - 100,myImage.Height - 100),
                    System.Drawing.Imaging.PixelFormat.DontCare);
    return croppedBitmap;
}

您必须删除两次 高度和宽度的边距:

public static Bitmap Crop(Image myImage)
{
    Bitmap croppedBitmap = new Bitmap(myImage);
    croppedBitmap = croppedBitmap.Clone(
                    new Rectangle(100,100,myImage.Width - 200,myImage.Height - 200),
                    System.Drawing.Imaging.PixelFormat.DontCare);
    return croppedBitmap;
}

另外,根据你的图片post,似乎没有左右边距,但你确实尝试在代码中删除。