从顶部颤动裁剪图像

时间:2021-02-22 14:59:02

标签: flutter

我有这个代码可以在颤振中居中裁剪图像:

 Future loadImage() async {
    final imageBytes = File(imageFilePath).readAsBytesSync();
    final newImage = img.decodeImage(imageBytes);
    var cropSize = min(newImage.width, newImage.height);
    print(cropSize.toString() + " cropsizeeeeee");
    int offsetX = (newImage.width - min(newImage.width, newImage.height)) ~/ 2;
    int offsetY = (newImage.height - min(newImage.width, newImage.height)) ~/ 2;
    print(offsetX.toString() + " offsetXxxxxxxxxx");
    print(offsetY.toString() + " offsetYyyyyyyyyyyyyyyy");
    img.Image destImage = img.copyCrop(newImage, offsetX, offsetY, cropSize, cropSize);
    if (widget.flip) {
      destImage = img.flipHorizontal(destImage);
    }

    if (widget.crop) {
      setState(() {
        this.image = destImage;
      });
      saveImage(destImage);
    } else {
      setState(() {
        this.image = newImage;
      });
      saveImage(newImage);
    }
  ]
  }

但由于项目要求的变化,我想从顶部裁剪图像。我无法计算 x 和 y 偏移量以从顶部获取图像。如何从顶部裁剪图像?

这是我想要的输出:enter image description here

这是我得到的输出: enter image description here

0 个答案:

没有答案