简介
使用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));}
gif原图
结果图
magick 合并
magick.exe convert frame_0.png frame_1.png frame_2.png out1.gif
magick 拆分
magick.exe convert out1.gif -coalesce o_%d.png