import 'dart:ui' as ui;
import 'package:image/image.dart' as img;
final double left = ...;
final double top = ...;
final double width = ...;
final double height = ...;
final bytes = File(image.path).readAsBytesSync();
final rawImage = img.decodeImage(bytes);
final pictureRecorder = ui.PictureRecorder();
final canvas = Canvas(pictureRecorder);
final paint = Paint();
canvas.drawImage(imgCodec, Offset.zero, paint);
final croppedImage = img.copyCrop(
rawImage,
left.toInt(),
top.toInt(),
width.toInt(),
height.toInt(),
);
final croppedBytes = img.encodePng(croppedImage);
final croppedImageFile = await saveImageToDisk(croppedBytes);
model.img = croppedImageFile.path;
1条答案
按热度按时间yi0zb3m41#
为此,您可以使用copyCrop函数。这里有一个例子
在上面的代码中,替换...与裁剪矩形的实际值。