如何在 Flutter 中解析本地文件中的动画 gif 图片?

问题描述 投票:0回答:0

我能够从资产中逐帧解析动画 gif(见下文)。但是,我无法使用本地动画 gif 文件。

static Future parseGif(String assetPath) async {
    List<ui.Image> gifImage = [];
    ByteData data = await rootBundle.load(assetPath);
    var codec = await ui.instantiateImageCodec(data.buffer.asUint8List());
    int frmCnt = codec.frameCount;
    for (int i = 0; i < frmCnt; i++) {
      var frame = await codec.getNextFrame();
      gifImage.add(frame. Image);
    }
}

我尝试了以下但它不起作用。我怎样才能从本地文件中获得与从资产

ByteData
返回的相同
rootBundle

final XFile? pickedImage =
        await picker.pickImage(source: ImageSource.gallery, imageQuality: 100);
    Uint8List bytes=File(pickedImage.path).readAsBytesSync();
var codec = await ui.instantiateImageCodec(bytes);
...
flutter parsing animation gif
© www.soinside.com 2019 - 2024. All rights reserved.