【问题标题】:How to convert image dpi (Dots per inch) in dart flutter?如何在飞镖颤动中转换图像 dpi(每英寸点数)?
【发布时间】:2021-08-28 07:18:57
【问题描述】:

问题与各种图像(例如 jpeg 或 png )格式的(打印)DPI 有关。

此问题与屏幕 DPI 或各种 Android 设备的尺寸无关。它也与在设备上以屏幕大小显示位图无关。

【问题讨论】:

    标签: java android ios flutter dart


    【解决方案1】:

    这会将图像分辨率每英寸点数转换为 300。

    Uint8List resultBytes = provider.bytes;
      print(resultBytes.toString());
      
      var dpi = 300;
      resultBytes[13] = 1;
      resultBytes[14] = (dpi >> 8);
      resultBytes[15] = (dpi & 0xff);
      resultBytes[16] = (dpi >> 8);
      resultBytes[17] = (dpi & 0xff);
    
      print(resultBytes.toString());
    
      String tempPath = (await getTemporaryDirectory()).path;
      String imgName = "IMG" + DateTime.now().microsecondsSinceEpoch.toString()+".jpg";
      File file = File('$tempPath/$imgName');
      await file.writeAsBytes(resultBytes);
    
      /**You will not be able to see the image in android local storage, so rewriting the file, using the code below will show you image in Pictures Directory of android storage. Note: ImageGallerySaver is plugin, just copy and paste the dependency and have a go.*/
    
      final result1 = ImageGallerySaver.saveFile(file.path);
      print(result1);
    

    【讨论】:

      猜你喜欢
      • 2014-11-03
      • 1970-01-01
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2021-10-07
      相关资源
      最近更新 更多