搜尋套件、儲存庫與 APP 分類

blurhash_ffi 封面
套件詳情v1.2.7

blurhash_ffi

一個緊湊、快速且易於使用的模糊圖像佔位符產生器,適用於 Flutter,使用原生 FFI 繫結。

AndroidiOSmacOSWindowsLinux
近 30 天下載
3150
喜歡數
107
Pub 分數
130

安裝套件

flutter pub add blurhash_ffi

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

blurhash_ffi 是一個高效率的 Flutter 套件,利用原生 FFI 繫結產生緊湊且視覺上吸引人的模糊圖像佔位符。它高效地編碼和解碼 BlurHash 字串,實現快速佔位符渲染,而不依賴純 Dart 實作。非常適合在圖像載入期間提升感知效能,支援 Android、iOS、macOS、Windows 和 Linux。此套件優先考慮速度與最小記憶體使用量,同時維持視覺品質。

適用情境

  • 加載畫面佔位符
  • 圖像畫廊預覽
  • 網絡圖像加載指示器
  • 離線內容佔位符
  • 媒體密集型應用中的性能優化

主要特色

  • 原生 FFI 性能
  • 跨平台支援
  • 緊湊哈希編碼
  • 快速解碼
  • 低記憶體佔用

適合對象

  • 載入大量圖片的應用
  • 高性能UI需求
  • 尋求原生速度的開發者
  • 需要輕量級佔位符的項目
  • 跨平台 Flutter 應用

使用建議

  • 需要原生編譯設定
  • 僅限 BlurHash 格式
  • 可能會稍微增加應用大小
  • 不適用於複雜的影像處理
  • 依賴於平台特定的 FFI 庫

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

blurhash_ffi

A Blurhash compact Image placeholder encoder and decoder FFI implementation for Flutter in Rust via experemental feature Native Assets.

Matches the official Blurhash implementation in performance and quality.

blurhash_ffi

Supports

Platform Status Description
Android ✅ -
iOS ✅ -
macOS ✅ -
Linux ⚠️ Not tested
Windows ✅ -
Web ❌ Rust can compiled to WebAssembly, but no supported yet. This library compiled on standalone wasm module (not in Empscripten, AssemblyScript) that Dart can't be use non-JS enviroments. Also, Dart should use FFI bindings for call wasm module. Stopped issues: comment

Installation

Add dependency to your pubspec.yaml file following the command below:

For dart projects:

dart pub add dart_blurhash_ffi

For flutter projects:

dart pub add flutter_blurhash_ffi

Usage

To use this plugin, add blurhash_ffi as a dependency in your pubspec.yaml file

Flutter usage

import 'package:flutter_blurhash_ffi/flutter_blurhash_ffi.dart';

/// Encoding and Decoding all in One Step
///
/// `ImageProvider` in    -> Send your Image to be encoded.
/// `ImageProvider` out   -> Get your blurry image version.
class BlurhashMyImage extends StatelessWidget {
  final String imageUrl;
  const BlurhashMyImage({required this.imageUrl, super.key});

  @override
  Widget build(BuildContext context) {
    return Image(
      image: BlurhashFfiImage.fromImageProvider(
        NetworkImage(imageUrl),  // you can use any image provider of your choice.
        decodingHeight: 1920,
        decodingWidth: 1080,
      ),
      alignment: Alignment.center,
      fit: BoxFit.cover
    );
  }
}


class BlurhashMyImage2 extends StatelessWidget {
  final String blurhash;
  const BlurhashMyImage2({required this.blurhash, super.key});

  @override
  Widget build(BuildContext context) {
    return Image(
      image: BlurhashFfiImage(blurhash),
      width: 200,
      height: 200,
      alignment: Alignment.center,
      fit: BoxFit.cover
    );
  }
}

[!WARNING] Not recommend use it (without blurhash string param), because in this case, encoding and decoding will be performed. This effect can be obtained almost through ImageFiltered.

Encoding

Encoding now uses sync interface (without Future).

import 'package:dart_blurhash_ffi/dart_blurhash_ffi.dart';

final Uint8List blurhashImageBytes = File('assets/image.webp').readAsBytesSync();

/// Signature
/// static String encode(
///   Uint8List data, {
///   int componentX = 4,
///   int componentY = 3,
/// })
/// may throw `BlurhashFFIException` if encoding fails.
final String blurHash = BlurhashFFI.encode(blurhashImageBytes);

// Or via codec

final String blurHashSame = BlurhashFfiCodec().encoder.convert(blurhashImageBytes);

Decoding

Decoding now uses sync interface (without Future).

import 'package:dart_blurhash_ffi/dart_blurhash_ffi.dart';

final String blurhash = 'LGFO~6Yk^6#M@-5c,1Ex@@or[j6o';

/// Signature
///
/// static Uint8List decode(
///   String blurhash, {
///   int width = 32,
///   int height = 32,
///   int punch = 1,
/// })
/// may throw `BlurhashFFIException` if decoding fails.
final decoded = BlurhashFFI.decode(blurhash);

// or via codec

final String decodedSame = BlurhashFfiCodec().decoder.convert(blurhash);

Check the example for more details

contributions in the form of PR's and Issues are a welcome

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。