How to get a Flutter Uint8List from a Network Image?

前端 未结 3 516
栀梦
栀梦 2020-12-18 22:55

I\'m trying to convert a network image into a file and the first part of that is to convert it into a Uint8List. Here is how I\'m doing this with 1 of my asset images...

3条回答
  •  半阙折子戏
    2020-12-18 23:33

      void initState() {
        super.initState();
        var sunImage = new NetworkImage(
            "https://resources.ninghao.org/images/childhood-in-a-picture.jpg");
        sunImage.obtainKey(new ImageConfiguration()).then((val) {
          var load = sunImage.load(val);
          load.addListener((listener, err) async {
            setState(() => image = listener);
          });
        });
      }
    

    See also https://github.com/flutter/flutter/issues/23761#issuecomment-434606683

    Then you can use image.toByteData().buffer.asUInt8List()

    See also https://docs.flutter.io/flutter/dart-ui/Image/toByteData.html

提交回复
热议问题