2023-06-06 - 获取图片压缩功能


  @override
  Future thumbnail(String args) async {
    final path = args.isNotEmpty ? args : 'test.png';
    VRUtils.pathTothumbnail(args).then((value) async {
////判断缩略图是否存在
      File txt = File(value);
      var dir_bool = await txt.exists(); //返回真假
      if (dir_bool) {
        return;
      }
      final cmd = img.Command()
        // Decode the image file at the given path
        ..decodeImageFile(path)
        // Resize the image to a width of 64 pixels and a height that maintains the aspect ratio of the original.
        ..copyResize(width: 64)
        // Write the image to a PNG file (determined by the suffix of the file path).
        ..writeToFile(value);
      // On platforms that support Isolates, execute the image commands asynchronously on an isolate thread.
      // Otherwise, the commands will be executed synchronously.
      await cmd.executeThread().then((value) {
        if (mounted) {
          setState(() {});
        }
      });
    });
  }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容