cutFaceImageFromImageBytes function

Future<Image> cutFaceImageFromImageBytes(
  1. Uint8List imgBytes,
  2. Rectangle rect
)

Cuts out the face from encoded image imgBytes

Implementation

Future<imglib.Image> cutFaceImageFromImageBytes(Uint8List imgBytes, Rectangle rect) async {
  var img = await decodeImageFromList(imgBytes);
  final bytes = await img.toByteData(format: ImageByteFormat.rawRgba);

  Uint8List _bytes = bytes!.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes);
  imglib.Image bufImage = imglib.Image.fromBytes(width: img.width, height: img.height, bytes: _bytes.buffer, order: imglib.ChannelOrder.rgba);
  final img2 = imglib.copyCrop(bufImage, x: rect.x, y: rect.y, width: rect.width, height: rect.height);

  return img2;
}