如何裁剪位图并获取图像的下 50%
How to crop bitmap and get the lower 50% of the Image
我有一张图片要裁剪。我已经知道我需要的内容位于图像的下半部分,那么如何使用 Rectangle 自动裁剪它?
我尝试使用此代码(下方)进行裁剪,但没有帮助。我没怎么用过Rectangle,请多多指教。
private Bitmap cropImage(Bitmap img)
{
int height= img.Height / 2;
Rectangle CropArea = new Rectangle(100,height, 1400, 900);
Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
return bmpCrop;
}
裁剪后的图像效果很好,但它是硬编码的。我需要让它动态化,以便它为不同的图像提供相同的结果
感谢@John 的回答。此代码将剪切图像的 50% 并给出图像的下半部分:
private Bitmap cropImage(Bitmap img)
{
int height= img.Height / 2;
int newWidth = img.Width -100;
int newHeight = img.Height - height;
Rectangle CropArea = new Rectangle(100,height,newWidth,newHeight);
Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
return bmpCrop;
}
我有一张图片要裁剪。我已经知道我需要的内容位于图像的下半部分,那么如何使用 Rectangle 自动裁剪它?
我尝试使用此代码(下方)进行裁剪,但没有帮助。我没怎么用过Rectangle,请多多指教。
private Bitmap cropImage(Bitmap img)
{
int height= img.Height / 2;
Rectangle CropArea = new Rectangle(100,height, 1400, 900);
Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
return bmpCrop;
}
裁剪后的图像效果很好,但它是硬编码的。我需要让它动态化,以便它为不同的图像提供相同的结果
感谢@John 的回答。此代码将剪切图像的 50% 并给出图像的下半部分:
private Bitmap cropImage(Bitmap img)
{
int height= img.Height / 2;
int newWidth = img.Width -100;
int newHeight = img.Height - height;
Rectangle CropArea = new Rectangle(100,height,newWidth,newHeight);
Bitmap bmpCrop = img.Clone(CropArea, img.PixelFormat);
return bmpCrop;
}