[英]How to Crop Bitmap with RectangleF as bounds
I am trying to crop a certain image with the RectangleF bounds I have. 我正在尝试使用我的RectangleF边界裁剪特定的图像。 The following code works great in iOS (for my needs) using an UIImage as source: 以下代码使用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;
}
}
I would like to have this same kind of function for Bitmaps in Android. 我想为Android中的位图使用相同的功能。
I tried the following, but not with the expected outcome: 我尝试了以下方法,但未达到预期的结果:
//Crop a certain rectangle of your image
Bitmap CropImage(Bitmap srcImage, RectangleF rect)
{
return Bitmap.CreateScaledBitmap(srcImage, (int)rect.Width,
(int)rect.Height, false);
}
All ideas are welcome! 欢迎所有想法!
// bmp - source bitmap
// x, y = origin for crop
// w, h = size of cropped image
return Bitmap.CreateBitmap(bmp, x, y, w, h);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.