cropImage function

Future<Uint8List> cropImage(
  1. String path,
  2. int x,
  3. int y,
  4. int w,
  5. int h,
)

Implementation

Future<Uint8List> cropImage(String path, int x, int y, int w, int h) async {
  Uint8List imageBytes = await File(path).readAsBytes();

  Image croppedImage = copyCrop(decodeImage(imageBytes)!, x, y, w, h);
  List<int> croppedList = encodePng(croppedImage);
  Uint8List croppedBytes = Uint8List.fromList(croppedList);
  // File savedImage = await File("/0").writeAsBytes(croppedBytes);
  return croppedBytes;
}