【发布时间】:2021-01-20 04:02:04
【问题描述】:
【问题讨论】:
标签: image flutter image-processing
【问题讨论】:
标签: image flutter image-processing
经过三天的努力,我终于找到了解决方法。 因此,如果它不是橡皮擦,我只是像往常一样画画,但如果橡皮擦我用着色器替换 Paint,那是我的背景图像。
if (!_eraser) {
paint = new Paint()
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round
..color = selectedColor
..strokeWidth = strokeWidth;
} else {
final Float64List deviceTransform = new Float64List(16)
..[0] = devicePixelRatio
..[5] = devicePixelRatio
..[10] = 1.0
..[15] = 2.0;
paint = new Paint()
..style = PaintingStyle.fill
..strokeCap = StrokeCap.round
..shader = ImageShader(image, TileMode.repeated, TileMode.repeated, deviceTransform)
..strokeWidth = strokeWidth;
绘画课
@override
void paint(Canvas canvas, Size size) {
canvas.drawImage(image, Offset.zero, new Paint());
for (int i = 0; i < pointsList.length - 1; i++) {
if (pointsList[i] != null && pointsList[i + 1] != null) {
canvas.drawLine(pointsList[i].points, pointsList[i + 1].points, pointsList[i].paint);
} else if (pointsList[i] != null && pointsList[i + 1] == null) {
offsetPoints.clear();
offsetPoints.add(pointsList[i].points);
offsetPoints.add(Offset(pointsList[i].points.dx + 0.1, pointsList[i].points.dy + 0.1));
canvas.drawCircle(pointsList[i].points, pointsList[i].paint.strokeWidth / 2, pointsList[i].paint);
}
}
}
【讨论】:
如果您想根据已有的用户输入裁剪图像,可以使用image 库中的copyCrop 函数。
【讨论】: