imencodeAsync function
Implementation
Future<(bool, Uint8List)> imencodeAsync(
String ext,
InputArray img, {
VecI32? params,
}) async {
final buffer = calloc<cvg.VecUChar>();
final pSuccess = calloc<ffi.Bool>();
final cExt = ext.toNativeUtf8().cast<ffi.Char>();
void completeFunc(Completer<(bool, Uint8List)> c) {
final success = pSuccess.value;
calloc.free(cExt);
calloc.free(pSuccess);
final vec = VecUChar.fromPointer(buffer);
final u8List = vec.toU8List(); // will copy data
vec.dispose();
return c.complete((success, u8List));
}
if (params == null) {
return cvRunAsync0(
(callback) => cimgcodecs.cv_imencode(cExt, img.ref, pSuccess, buffer, callback),
completeFunc,
);
}
return cvRunAsync0(
(callback) => cimgcodecs.cv_imencode_1(cExt, img.ref, params.ref, pSuccess, buffer, callback),
completeFunc,
);
}