blurhash_dart
BlurHash 알고리즘의 순수한 다트 구현입니다. 이 패키지는 인코더와 디코더를 제공하며, 몇 가지 유틸리티 확장 기능도 포함되어 있습니다.
blurhash의 순수한 다트 구현
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
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.
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...
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.
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);
Additional extension methods to compute, for example color averages, are available
when importing package:blurhash_dart/blurhash_extensions.dart. See example for
basic usage.