【问题标题】:Flutter image processing causing pixelation颤振图像处理导致像素化
【发布时间】:2020-07-29 16:45:32
【问题描述】:

正在处理一个颤振项目,该项目需要在上传到服务器之前拍照并将图像调整大小/裁剪到 640 / 420 (15:10),但它们似乎失去了太多质量和像素化。

      img.Image image = img.decodeImage(a2);
      double width = (image.height / 10) * 15;
      image = img.copyCrop(image, ((image.width - width) / 2).round(), 0, width.round(), image.height);
      resized = img.encodeJpg(img.copyResize(image, width:640, interpolation: img.Interpolation.cubic));

目前使用camera 以720p (1280x720) 拍摄,使用image 插件进行裁剪并使用平均插值调整大小。

我主要想知道这是否是处理图像处理以保持最高质量的最佳方法,或者是否有针对此用例的更好方法。

【问题讨论】:

    标签: flutter image-processing dart


    【解决方案1】:

    你应该试试这个方法,我自己一直在使用下面的方法,效果很好,图像也没有损失任何质量,而且尺寸太压缩了

    final _tempDir = await getTemporaryDirectory();
        final _path = _tempDir.path;
        im.Image imageFile = im.decodeImage(_file.readAsBytesSync());
        mealID = Uuid().v4();
        final compressedImageFile = File('$_path/img_$mealID.jpg')
          ..writeAsBytesSync(im.encodeJpg(imageFile, quality: 80));
        setState(() {
          _file = compressedImageFile;
        });
    

    上述方法是用于压缩图像,以及从图库/相机中捕获图像,我使用以下方法。

    
      Future getImageFromCamera() async {
        Navigator.pop(context);
        var image = await ImagePicker.pickImage(
          source: ImageSource.camera,
          imageQuality: 50,
          /*you can set max height and/or width here as well just by setting value for maxHeight and/or maxWidth argument*/
        );
        setState(() {
          _file = image;
        });
        await compressImage();
      }
    
      Future getImageFromGallery() async {
        Navigator.pop(context);
        var image = await ImagePicker.pickImage(
          source: ImageSource.gallery,
          imageQuality: 50,
        );
        setState(() {
          _file = image;
        });
        await compressImage();
      }
    

    【讨论】:

      猜你喜欢
      • 2022-06-22
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2021-03-11
      • 2021-05-10
      • 2020-10-01
      • 2022-01-15
      相关资源
      最近更新 更多