flutter_image_compress 0.1.1 copy "flutter_image_compress: ^0.1.1" to clipboard
flutter_image_compress: ^0.1.1 copied to clipboard

outdated

compress image with native code(objc kotlin), it's faster.

flutter_image_compress #

compress image with native code(objc kotlin)

why #

Q:Dart has image related libraries to compress. Why use native?

A:For efficiency reasons, the compression efficiency of some dart libraries is not high, and it will be stuck to UI, even if isolate is used.

use #

dependencies:
  flutter_image_compress: ^0.1.0
import 'package:flutter_image_compress/flutter_image_compress.dart';

compress with file path

 var img = AssetImage("img/img.jpg");
    print("pre compress");
    var config = new ImageConfiguration();

    AssetBundleImageKey key = await img.obtainKey(config);
    final ByteData data = await key.bundle.load(key.name);
    File file = File("test.png");
    file.writeAsBytesSync(data.buffer.asUint8List());
    
    var result = await FlutterImageCompress.compressWithFile(
      file.absolute.path, // file path
      minWidth: 2300,
      minHeight: 1500,
      quality: 94,
    ); // compress
    print(file.lengthSync());
    print(result.length);

compress with list

  Future<void> compress() async {
    var img = AssetImage("img/img.jpg");
    print("pre compress");
    var config = new ImageConfiguration();

    AssetBundleImageKey key = await img.obtainKey(config);
    final ByteData data = await key.bundle.load(key.name);

    var beforeCompress = data.lengthInBytes;
    print("beforeCompress = $beforeCompress");

    var result =
        await FlutterImageCompress.compressWithList(
      data.buffer.asUint8List(), //list 
      minWidth: 2300,
      minHeight: 1500,
      quality: 94,
    );

    print("after = ${result?.length ?? 0}");
  }
1324
likes
0
pub points
99%
popularity

Publisher

verified publisherfluttercandies.com

compress image with native code(objc kotlin), it's faster.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_image_compress