【问题标题】:Crop image from uInt8List Flutter从 uInt8List Flutter 裁剪图像
【发布时间】:2020-05-06 15:56:49
【问题描述】:

我正在开发一个用于发布图像的工具,例如 instagram,

问题是我想剪切图像并发送到服务器方,我的问题是无法从原始图像中剪切图像方,我的图像中有一个 uInt8List。

如何剪切我的图像?

【问题讨论】:

    标签: image flutter crop


    【解决方案1】:

    我从 Firebase 的 Vision Api 编写了一个关于 Face 的扩展,它会返回图像字节数据,您可以将其插入到 Image.memory 小部件中。 忘记提及您需要图像库: - https://pub.dev/packages/image

    extension FaceExtension on Face {
     Future<Uint8List> getFaceFromImage(File imageFile) async {
        final image = await imageFile.readAsBytes();
        final decodedImage = decodeImage(image);
    
        final rectangle = this.boundingBox;
    
        final face = copyCrop(
          decodedImage,
          rectangle.topLeft.dx.toInt(),
          rectangle.topLeft.dy.toInt(),
          rectangle.width.toInt(),
          rectangle.height.toInt(),
        );
    
        return Uint8List.fromList(encodePng(face));
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-05-25
      • 2021-06-24
      • 2016-08-14
      • 2016-02-06
      • 2013-04-02
      • 1970-01-01
      • 2017-05-22
      • 2020-11-01
      • 2020-12-14
      相关资源
      最近更新 更多