Image 向图像添加文本并存储-颤振

Image 向图像添加文本并存储-颤振,image,flutter,Image,Flutter,您好,我正在生成证书,为此我有一个模板,我必须在其中写入用户数据,目前我正在以pdf格式创建证书,但理想情况是使用图像或将这些pdf转换为图像,因为用户更容易处理图像,我还没有找到任何能够正确书写图像的库 目前我正在尝试使用图像 我有以下代码,但它无法在图像中添加文本片段 imagecert = await ManagerDB().getcertificate(certificatetemplate); //imagecert is uint8list if (imagecert !=

您好,我正在生成证书,为此我有一个模板,我必须在其中写入用户数据,目前我正在以pdf格式创建证书,但理想情况是使用图像或将这些pdf转换为图像,因为用户更容易处理图像,我还没有找到任何能够正确书写图像的库

目前我正在尝试使用图像

我有以下代码,但它无法在图像中添加文本片段

 imagecert = await ManagerDB().getcertificate(certificatetemplate); //imagecert is uint8list
    if (imagecert != null) {

      mg.Image ima = mg.Image.fromBytes(300, 200, List.from(imagecert)); Image works with list<int>
      mg.Image imag = mg.drawString(ima, mg.arial_14, 0, 0, 'Hello World'); //here the code does not work
      List<int> data = mg.encodePng(imag);
      Uint8List bytes = Uint8List.fromList(data);
      setState(() {});
      return bytes;
    } else {
      print("Enlace no encontrado");
    }
imagecert=wait ManagerDB().getcertificate(certificatetemplate)//imagecert是UInt8列表
如果(imagecert!=null){
mg.Image ima=mg.Image.fromBytes(300200,List.from(imagecert));Image与List一起工作
mg.Image imag=mg.drawString(ima,mg.arial_14,0,0,'Hello World');//这里的代码不起作用
列表数据=mg.encodePng(imag);
Uint8List字节=Uint8List.fromList(数据);
setState((){});
返回字节;
}否则{
打印(“Enlace无需输入”);
}
我不知道是否有一个更简单的解决方案来在图像中写入文本。需要存储这些图像


谢谢

您可以将图像放入小部件并添加到该小部件文本中 并使用globalKey转换为图像(别忘了将globalKey传递给那个单独的小部件的键)


Future\u convertWidgetToImage(GlobalKey-GlobalKey)异步{
渲染边界=
globalKey.currentContext!.FindEnderObject()作为RenderPaintBoundary;
ui.Image=wait boundary.toImage();
ByteData ByteData=
(wait(image.toByteData(格式:ui.ImageByteFormat.png))!;
Uint8List pngBytes=byteData.buffer.asUint8List();
返回PNG字节;
}