搜索分类、插件与代码仓

插件详情v1.2.1

blurhash_dart

BlurHash 算法的纯 Dart 实现。此包提供了编码器和解码器,以及一些实用的扩展。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
11.3万
喜欢数
135
Pub 分数
160

安装插件

flutter pub add blurhash_dart

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

BlurHash Dart 是 BlurHash 算法的纯 Dart 实现,可高效生成和解码紧凑的图像占位符。它提供编码器和解码器功能以及有用的工具扩展,便于无缝集成到 Flutter 应用中。非常适合在加载期间显示低带宽的图像预览,支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。该包轻量且专为性能设计,无需外部依赖。

适合场景

  • 在加载期间生成图像占位符
  • 为大图像创建低分辨率预览
  • 通过占位符视觉效果提升应用性能的感知
  • 在图像缩略图中集成模糊效果
  • 在网络密集型应用中优化图像加载

主要特点

  • 纯 Dart 实现
  • 包含编码器和解码器
  • 实用扩展,便于使用
  • 跨平台兼容性
  • 轻便且快速
  • 无原生依赖

适合对象

  • Flutter 开发者需要图像占位符
  • 网络条件缓慢或不稳定的App
  • 面向性能的 UI 实现
  • 开发者避免使用平台特定代码
  • 需要最少第三方库的项目

使用建议

  • 不适合高保真图像表示
  • 需要理解 BlurHash 概念
  • 仅限占位符使用场景
  • 可能不支持高级图像处理功能
  • 最好用作视觉增强,而不是实际图像的替代品

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

BlurHash Dart

A pure dart implementation of BlurHash. Supports both encoding and decoding. Runs on every supported Dart platform. See the BlurHash website or GitHub repository for more information.

The encoder of this dart implementation produces slightly different hashes than the TypeScript implementation but matches the official C and Python implementation. In practice this should not be relevant.

Basic usage

Decoding a BlurHash
import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:image/image.dart' as img;

const hash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
BlurHash blurHash = BlurHash.decode(hash);
img.Image image = blurHash.toImage(35, 20);

// Display image...
Note: Usage with Flutter

Flutter does not expect raw bytes for its Image.memory widget, but fully encoded images with their corresponding headers (e.g. bitmap, jpg, png). The easiest way to accomplish this, is to use, for example, encodeJpg from package:image:

Widget build(BuildContext context) {
  final image = BlurHash.decode('LEHV6nWB2yk8pyo0adR*.7kCMdnj').toImage(35, 20);
  return Image.memory(Uint8List.fromList(encodeJpg(image)));
}

It is recommended to cache the resulting image in a stateful widget, such that it does not need to be recomputed on every build call.

Encoding an Image
import 'dart:io';

import 'package:blurhash_dart/blurhash_dart.dart';
import 'package:image/image.dart' as img;

final data = File('path/to/image.png').readAsBytesSync();
final image = img.decodeImage(data.toList());
final blurHash = BlurHash.encode(image!, numCompX: 4, numCompY: 3);

print(blurHash.hash);
Extension Methods

Additional extension methods to compute, for example color averages, are available when importing package:blurhash_dart/blurhash_extensions.dart. See example for basic usage.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目