我们可以在Flutter中裁剪具有点和大小的图像吗?

时间:2019-08-22 04:04:55

标签: flutter

我正在编写一个面部检测应用程序,我想使用该面部的边界框裁剪在屏幕上检测到的面部。

我一直进行搜索,但是只能以宽高和宽高比进行裁剪。

我不想像其他图像裁剪插件一样裁剪手册,因为它们也具有宽度,高宽比。

1 个答案:

答案 0 :(得分:2)

您可以使用https://github.com/brendan-duncan/image

对于您的情况,请尝试使用copyCrop

https://github.com/brendan-duncan/image/blob/master/lib/src/transform/copy_crop.dart

copy_crop.dart

import '../image.dart';

/// Returns a cropped copy of [src].
Image copyCrop(Image src, int x, int y, int w, int h) {
  Image dst = Image(w, h, channels: src.channels, exif: src.exif,
      iccp: src.iccProfile);

  for (int yi = 0, sy = y; yi < h; ++yi, ++sy) {
    for (int xi = 0, sx = x; xi < w; ++xi, ++sx) {
      dst.setPixel(xi, yi, src.getPixel(sx, sy));
    }
  }

  return dst;
}

用法

var croppedImage = Image copyCrop(Image sampleImageSrc, int pointX, int pointY, int desiredWidth, int desiredHeight);
相关问题