简体   繁体   English

如何在 Flutter 中将图像转换为二维码?

[英]How to convert an Image into a QR code in Flutter?

I am trying to convert an image into a QR code and read the qr code to construct back the image.我正在尝试将图像转换为二维码并读取二维码以构造回图像。 I can place an image in the center of a QR code using qr_flutter but I am unable figure out a way to represent an entire image as a QR code (possibly QR 40).我可以使用 qr_flutter 将图像放置在 QR 码的中心,但我无法找到将整个图像表示为 QR 码(可能是 QR 40)的方法。 If anyone can help me with this, it will be really helpful.如果有人可以帮助我解决这个问题,那将非常有帮助。

Future<Uint8List> _getWidgetImage() async {
 try {
   RenderRepaintBoundary boundary =
      _renderObjectKey.currentContext.findRenderObject();
   ui.Image image = await boundary.toImage(pixelRatio: 3.0);
   ByteData byteData =
      await image.toByteData(format: ui.ImageByteFormat.png);
   var pngBytes = byteData.buffer.asUint8List();
   var bs64 = base64Encode(pngBytes);
   debugPrint(bs64.length.toString());
   return pngBytes;
 } catch (exception) {}
}

@override
Widget build(BuildContext context) {
    return Scaffold(
        body: Column(children: [
          RepaintBoundary(
            key: _renderObjectKey,
            child: QrImage(
            data: "some text",
            size: 300.0,
            version: 10,
            backgroundColor: Colors.white,
         ),
       ),
       RaisedButton(onPressed: () {
         _getWidgetImage();
       })
     ]));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM