Flutter BlurHash 是一个轻量级包,可使用 BlurHash 编码实时生成图像的紧凑占位符。它将图像的模糊版本编码为一段短字符串(少于 30 个字符),可在加载时立即显示——非常适合提升图像密集型应用的感知性能。编码后的哈希值可直接渲染为占位符,模拟实际图像加载前的颜色和结构。该方法被 Medium 等平台广泛采用,以提升用户体验。
适合场景
图像加载占位符
媒体密集型应用中的性能优化
在图像获取过程中即时视觉反馈
渐进式图像渲染
减少感知加载时间
离线图像预览
主要特点
超紧凑哈希表示
实时占位符生成
保留色彩的模糊效果
跨平台支持
与图像小部件的轻松集成
低带宽使用
适合对象
包含大量图片的应用
内容推送
社交媒体平台
电子商务应用
优先考虑流畅加载的UI
寻求快速图像占位符的开发者
使用建议
非常短的哈希值中细节有限
不适合用于高保真预览
需要在客户端进行解码
最适合低分辨率占位符
可能无法准确匹配复杂纹理
哈希必须预先计算或在服务器端生成
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
flutter_blurhash
Blurhash is compact representation of a blurred image.
It's often used as a placeholder while waiting for a full image to load.
This package implements the blurhash-decoding algorithm in pure Dart.
It also provides the BlurHash widget that displays the blurhash and can transition into the actual image once it is loaded.
Currently, it doesn't support encoding an image into a blurhash.
Generation
A fast and easy way to get a blurhash for your image is to upload it to https://blurha.sh.
Example
Constrain your widget's render area and let BlurHash fill the pixels.
None (BlurHashOptimizationMode.none): The original algorithm, provided for backward compatibility.
Standard (BlurHashOptimizationMode.standard): Optimized decoding with better cache locality and performance.
Approximation (BlurHashOptimizationMode.approximation): Fastest mode with an approximated sRGB conversion that produces slightly darker results but significantly improves performance.