【问题标题】:How to Crop Bitmap with RectangleF as bounds如何以 RectangleF 为边界裁剪位图
【发布时间】:2019-04-09 12:25:54
【问题描述】:

我正在尝试使用我拥有的 RectangleF 边界裁剪某个图像。 以下代码在 iOS 中运行良好(满足我的需要),使用 UIImage 作为源:

//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 中为 Bitmaps 提供同样的功能。

我尝试了以下方法,但没有达到预期的结果:

//Crop a certain rectangle of your image
Bitmap CropImage(Bitmap srcImage, RectangleF rect)
{ 
    return Bitmap.CreateScaledBitmap(srcImage, (int)rect.Width,   
    (int)rect.Height, false);  
}

欢迎所有想法!

【问题讨论】:

    标签: android ios xamarin bitmap


    【解决方案1】:
    // bmp - source bitmap
    // x, y = origin for crop
    // w, h = size of cropped image
    return Bitmap.CreateBitmap(bmp, x, y, w, h);
    

    【讨论】:

      猜你喜欢
      • 2018-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多