gpt4 book ai didi

dart - Flutter-如何在自定义 Paint 中调整图像的高度和宽度?

转载 作者:行者123 更新时间:2023-12-04 16:33:56 26 4
gpt4 key购买 nike

在这里,我将图像列表传递给 ImagePaint 类以将图像剪裁成圆形,图像剪裁很好,但只剪裁了图像的一部分,如果我可以减少图像的高度和宽度。然后它将适合圆圈,如果有任何想法,请发表评论。

void paint(Canvas canvas, Size size) {
int c = 0;
canvas.save();
canvas.translate(size.width / 2, size.height / 2);
canvas.rotate(-rotation);

for (var i = 0; i < 16; ++i) {
if (i % 2 == 0) {
canvas.drawLine(
new Offset(0.0, 0.0),
new Offset(0.0, size.width / 2 - 4.2),
tickPaint,
);
} else {
canvas.save();
canvas.translate(-0.0, -((size.width) / 2));
canvas.clipPath(path);
if (images[c] != null) {
ui.Image img = images[c];
canvas.drawImage(img, Offset(0.0, 0.0), new Paint());
}
canvas.rotate(2 * pi);
canvas.restore();
c++;
}
canvas.rotate(2 * pi / 16);
}
canvas.restore();}

此图像以圆形方式打印:
this image is printed in a circular manner

这是我的应用程序,我正在剪辑图像并以圆形打印:
This is my app I am clipping image and printing in circular

最佳答案

我只是想出了如何缩小图像并将其发送给画家进行绘画。

缩小图像的方法及其返回的内容被发送到绘图类。

如果它对您有用,请竖起大拇指感谢我的回复,谢谢。

import 'dart:ui' as ui;
import 'package:image/image.dart' as IMG;

Future<ui.Image> loadImage( List<int> data ) async {
final IMG.Image image = IMG.decodeImage(data);
final IMG.Image resized = IMG.copyResize(image, width: 200);
final List<int> resizedBytes = IMG.encodePng(resized);
final Completer<ui.Image> completer = new Completer();

ui.decodeImageFromList(resizedBytes, (ui.Image img) => completer.complete(img));
return completer.future;
}

绘画课。
class CustomDraw extends CustomPainter {
final ui.Image image;

const CustomDraw({this.image});

@override
void paint(Canvas canvas, Size size) {
Paint paint = new Paint();
canvas.drawImage(image, new Offset(40.0, 10.0), paint);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}

关于dart - Flutter-如何在自定义 Paint 中调整图像的高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51021459/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com