encodeJpeg static method
Encode RGBA pixels as a baseline JPEG (4:2:0).
Implementation
static Uint8List encodeJpeg(RgbaImage src, int quality) {
final input = calloc<Uint8>(src.bytes.length);
final cap = src.bytes.length + 4096;
final out = calloc<Uint8>(cap);
try {
input.asTypedList(src.bytes.length).setAll(0, src.bytes);
final n = _encodeJpeg(input, src.width, src.height, quality, out, cap);
if (n <= 0) throw StateError('JPEG encode failed');
return Uint8List.fromList(out.asTypedList(n));
} finally {
calloc.free(input);
calloc.free(out);
}
}