getFileNaturalSize static method

Size? getFileNaturalSize(
  1. String filePath
)

获取本地文件图片的天然像素尺寸(使用 image_size_getter,命中缓存则直接返回) filePath 支持普通路径或以 file:// 开头的路径

Implementation

static ui.Size? getFileNaturalSize(String filePath) {
  if (filePath.isEmpty) return null;
  String path = filePath;
  if (path.startsWith('file://')) {
    path = path.substring(7);
  }
  if (_filePathSizeCache.containsKey(path)) {
    return _filePathSizeCache[path];
  }

  try {
    final file = File(path);
    if (!file.existsSync()) return null;
    final result = ImageSizeGetter.getSizeResult(FileInput(file));
    final size =
        ui.Size(result.size.width.toDouble(), result.size.height.toDouble());
    _filePathSizeCache[path] = size;
    return size;
  } catch (e) {
    RCIMWrapperPlatform.instance.writeLog(
        'ImageUtil getFileNaturalSize error',
        '',
        0,
        'error: $e, path: $filePath');
    return null;
  }
}