边缘顶部和底部的裁剪图像

时间:2016-05-16 10:28:41

标签: c# crop

我有一张图片

image

我必须以“边距”顶部和底部裁剪。我写这段代码,但只能使用上边距

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;
}

1 个答案:

答案 0 :(得分:2)

您必须从高度和宽度移除两次边距:

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;
}

此外,根据您发布的图片,它似乎没有左右边距,但您确实尝试在代码中删除。

相关问题