搜尋分類、套件與程式碼儲存庫

套件詳情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 項

原始碼儲存庫

使用此套件的專案