繁体   English   中英

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

[英]Can we crop an image with point and size in Flutter?

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

我一直搜索,但只能用宽高和纵横比进行裁剪。

我不想像其他图像裁剪插件一样裁剪手动,因为它们也裁剪宽度高度和纵横比。

您可以为此使用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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM