从uInt8List Flutter裁剪图像

时间:2020-05-06 15:56:49

标签: image flutter crop

我正在开发一种发布instagram之类图像的工具,

enter image description here

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

我如何裁切图像?

1 个答案:

答案 0 :(得分:0)

我从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));
  }
}