我正在尝试使用我拥有的 RectangleF 边界裁剪某个图像。以下代码在使用 UIImage 作为源代码的 iOS 中效果很好(满足我的需求(:
//Crop a certain rectangle of your image
UIImage CropImage(UIImage srcImage, RectangleF rect)
{
using (CGImage cr = srcImage.CGImage.WithImageInRect(rect))
{
UIImage cropped = UIImage.FromImage(cr);
return cropped;
}
}
我想在Android中为位图提供相同的功能。
我尝试了以下方法,但没有达到预期的结果:
//Crop a certain rectangle of your image
Bitmap CropImage(Bitmap srcImage, RectangleF rect)
{
return Bitmap.CreateScaledBitmap(srcImage, (int)rect.Width,
(int)rect.Height, false);
}
欢迎所有想法!
// bmp - source bitmap
// x, y = origin for crop
// w, h = size of cropped image
return Bitmap.CreateBitmap(bmp, x, y, w, h);