getBase64NaturalSize static method
使用 image_size_getter 获取天然像素尺寸,未进行全图像素解码。
Implementation
static ui.Size? getBase64NaturalSize(String base64String) {
if (base64String.isEmpty) return null;
final entry = _touchBase64(base64String);
if (entry?.size != null) return entry!.size;
if (entry?.invalid == true) return null;
final bytes = getDecodedBase64(base64String);
ui.Size? size;
if (bytes != null) {
try {
final result = ImageSizeGetter.getSizeResult(MemoryInput(bytes));
size = _naturalSize(
result.size.width,
result.size.height,
needRotate: result.size.needRotate,
);
} catch (_) {}
}
// 按原输入的解码估值判断准入,避免超大合法数据仅留下巨型尺寸键。
if (base64String.length * 2 + ((base64String.length + 3) ~/ 4) * 3 + 128 <=
_maxBase64CacheBytes) {
_cacheBase64(
base64String,
_ImageCacheEntry(bytes: bytes, size: size, invalid: size == null),
);
}
return size;
}