繁体   English   中英

如何在 dart flutter 中转换图像 dpi(每英寸点数)?

[英]How to convert image dpi (Dots per inch) in dart flutter?

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

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

这会将图像分辨率每英寸点数转换为 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM