Your code reads an image imageCount() + 2 times. I expect the last two images are the problem children.
reader->read(image);
for(int index=0;index<=reader->imageCount();index++)
{
reader->jumpToNextImage();
reader->read(image);
image->save(frameName,"JPEG",100);
}
QImage* image = new QImage();
QImageReader* reader = new QImageReader(gif);
reader->read(image);
for(int index=0;index<=reader->imageCount();index++)
{
reader->jumpToNextImage();
reader->read(image);
QString frameName = dir + '/' + QString("out%1.jpg").arg(index,5,10,QChar('0'));
image->save(frameName,"JPEG",100);
}
To copy to clipboard, switch view to plain text mode
Line 3: reads first image in file (discarded)
Line 5: Loop of imageCount() + 1 iterations
Line 7: index == 0, jump to second image in file. index == 1, jump to third image...
Line 8: returns false (ignored) on last two loops
Try this on your problem image
qDebug() << "Count =" << reader.imageCount();
for (int index = 0; index < reader.imageCount(); ++index) {
if (reader.read(&image))
}
const QString gif("test.gif");
QImage image;
QImageReader reader(gif);
qDebug() << "Count =" << reader.imageCount();
for (int index = 0; index < reader.imageCount(); ++index) {
if (reader.read(&image))
image.save(QString("output%1.png").arg(index, 3, 10, QLatin1Char('0')));
}
To copy to clipboard, switch view to plain text mode
Bookmarks