'Dart Compress Uint8List Image
How do I compress a Uint8List image? The purpose to to get a smaller size (length in bytes). I'm trying to avoid converting the Uint8List to File before compression.
Solution 1:[1]
if you don't mind to use packages for it, you can use: flutter_image_compress
Solution 2:[2]
this worked for me
File imageFile = File.fromRawPath(uint8List);
var compressedImage = await testCompressFile(imageFile);
// compress file and get Uint8List
Future<Uint8List?> testCompressFile(File file) async {
Uint8List? result;
try {
result = await FlutterImageCompress.compressWithFile(
file.absolute.path,
minWidth: 500,
minHeight: 500,
quality: 94,
);
print(file.lengthSync());
print(result?.length);
} on UnsupportedError catch (e) {
print(e);
}
return result;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kherel |
Solution 2 | Noha El Sheweikh |