Quantcast
Channel: WP快站
Viewing all articles
Browse latest Browse all 233

In Flutter, how to extract frame by frame from an animated gif?

$
0
0

I'm trying to extract frames from an animated gif using Flutter. By researching the Flutter API, I thought the following code should work but it only gives me the first frame although it gives me the correct frames count.

static Future<List<ui.Image>> loadAnimatedGif(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;    print("frmcnt is $frmCnt"); //it gives correct frames count    for (int i = 0; i < frmCnt; i++) {      var frame = await codec.getNextFrame();      gifImage.add(frame.Image);    }    return gifImage;  }

Viewing all articles
Browse latest Browse all 233

Trending Articles