getFromFile method
Implementation
Future<File?> getFromFile(File file) async {
// Load the image from the file
final image = await _loadImageFromFile(file);
// Extract the part of the image inside the draggable container
final recorder = ui.PictureRecorder();
final canvas = Canvas(recorder);
final srcRect = Rect.fromLTWH(
_offset.dx * image.width / 301,
_offset.dy * image.height / 301,
_containerSize.width * image.width / 301,
_containerSize.height * image.height / 301,
);
final dstRect =
Rect.fromLTWH(0, 0, _containerSize.width, _containerSize.height);
canvas.drawImageRect(image, srcRect, dstRect, Paint());
// Convert the pixels to a byte buffer
final imageByteData = await recorder
.endRecording()
.toImage(_containerSize.width.toInt(), _containerSize.height.toInt());
final byteData =
await imageByteData.toByteData(format: ui.ImageByteFormat.png);
// Update the extracted image
_extractedImage = byteData!.buffer.asUint8List();
// Convert Uint8List to File
return _unit8ListToFile(_extractedImage!);
}