imencodeAsync function

Future<(bool, Uint8List)> imencodeAsync(
  1. String ext,
  2. InputArray img, {
  3. VecI32? params,
})

IMEncode encodes an image Mat into a memory buffer. This function compresses the image and stores it in the returned memory buffer, using the image format passed in in the form of a file extension string.

For further details, please see: http://docs.opencv.org/master/d4/da8/group__imgcodecs.html#ga461f9ac09887e47797a54567df3b8b63

Implementation

Future<(bool, Uint8List)> imencodeAsync(
  String ext,
  InputArray img, {
  VecI32? params,
}) async {
  final cExt = ext.toNativeUtf8().cast<ffi.Char>();
  final rval = cvRunAsync2<(bool, Uint8List)>(
    (callback) => params == null
        ? cffi.Image_IMEncode_Async(cExt, img.ref, callback)
        : cffi.Image_IMEncode_WithParams_Async(cExt, img.ref, params.ref, callback),
    (c, p, p1) {
      final v = p.cast<ffi.Bool>().value;
      calloc.free(p);
      final vec = VecUChar.fromPointer(p1.cast());
      final data = vec.toU8List();
      vec.dispose();
      return c.complete((v, data));
    },
  );
  return rval;
}