使用QMovie 将 gif 进行切帧, magick 进行合并
QString gifPath = "E:\\workspace\\qt\\gif2imgs\\203526qre64haq3ccoobqi.gif"; // 你的图片
QMovie movie(gifPath);
movie.setCacheMode(QMovie::CacheNone);
qDebug() << movie.frameCount();
int frameCount = movie.frameCount(); // 帧数
qDebug() << "Frame count:" << frameCount;
// 遍历每一帧并将其保存为图片
for (int i = 0; i < frameCount; ++i) {
qDebug() << "Jump Res: " << movie.jumpToFrame(i);
QPixmap pixmap = movie.currentPixmap();
pixmap.save(qApp->applicationDirPath() + QString("/frame_%1.png").arg(i));
}
magick.exe convert frame_0.png frame_1.png frame_2.png out1.gif
magick.exe convert out1.gif -coalesce o_%d.png