gpt4 book ai didi

canvas - Flutter:如何在 Canvas 上绘制图标?

转载 作者:行者123 更新时间:2023-12-01 11:06:45 26 4
gpt4 key购买 nike

我正在使用CustomPainter在Flutter中进行绘制,如下所示:

@override
void paint(Canvas canvas, Size size) {
canvas.drawRect(...);
canvas.drawImage(...);
...
}

如何在 Icon上绘制 canvas

最佳答案

创建一个包含正确字体的代码点的Paragraph,根据需要设置样式,然后绘制。

final icon = Icons.add;
var builder = ui.ParagraphBuilder(ui.ParagraphStyle(
fontFamily: icon.fontFamily,
))
..addText(String.fromCharCode(icon.codePoint));
var para = builder.build();
para.layout(const ui.ParagraphConstraints(width: 60));
canvas.drawParagraph(para, const Offset(20, 20));

关于canvas - Flutter:如何在 Canvas 上绘制图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57922017/

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