-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdither_it_example.dart
More file actions
30 lines (24 loc) · 906 Bytes
/
dither_it_example.dart
File metadata and controls
30 lines (24 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'dart:io';
import 'package:dither_it/dither_it.dart';
import 'package:image/image.dart';
void main() async {
// Load an image
final bytes = await File('example/input.png').readAsBytes();
final image = decodeImage(bytes)!;
// Try Floyd-Steinberg dithering
final floydSteinbergImage = DitherIt.floydSteinberg(image: image);
await File('example/output_floyd_steinberg.png').writeAsBytes(
encodePng(floydSteinbergImage),
);
// Try Ordered Dithering with 4x4 Bayer matrix
final orderedImage = DitherIt.ordered(image: image, matrixSize: 4);
await File('example/output_ordered.png').writeAsBytes(
encodePng(orderedImage),
);
// Try Riemersma Dithering
final riemersmaImage = DitherIt.riemersma(image: image);
await File('example/output_riemersma.png').writeAsBytes(
encodePng(riemersmaImage),
);
print('✅ Dithering complete! Check the output files.');
}