resizeImage function

Future<ByteData?> resizeImage(
  1. Uint8List rawImage, {
  2. int? width,
  3. int? height,
})

Resizes the image rawImage to width and height.

If only width or height are specified, the resized image will keep the aspect ratio.

Implementation

Future<ByteData?> resizeImage(Uint8List rawImage,
    {int? width, int? height}) async {
  final codec = await ui.instantiateImageCodec(rawImage,
      targetWidth: width, targetHeight: height);
  final resizedImage = (await codec.getNextFrame()).image;
  return resizedImage.toByteData(format: ui.ImageByteFormat.png);
}