gif record fixes

This commit is contained in:
Бычков Андрей
2022-06-24 14:09:29 +03:00
parent e5f23caeaa
commit af530b582c

View File

@@ -251,7 +251,7 @@ void Graphic::timerEvent(QTimerEvent * e) {
if (e->timerId() == timer_record) {
QPixmap im(canvas->size());
canvas->render(&im);
record_imgs << im.toImage();
record_imgs << im.toImage().convertToFormat(QImage::Format_Indexed8);
}
}
@@ -1934,6 +1934,7 @@ void Graphic::on_graphic_buttonRecord_clicked(bool checked) {
if (record_imgs.isEmpty()) return;
QString f = QFileDialog::getSaveFileName(this, tr("Save GIF"), ppath, "GIF(*.gif)");
if (!f.isEmpty()) {
qApp->setOverrideCursor(Qt::BusyCursor);
GifWriter gif_writer;
int frame_delay = 10;
if (GifBegin(&gif_writer, f.toUtf8(), static_cast<uint32_t>(record_imgs.first().width()),
@@ -1941,7 +1942,7 @@ void Graphic::on_graphic_buttonRecord_clicked(bool checked) {
static_cast<uint32_t>(frame_delay))) {
for (const QImage & im : record_imgs) {
if (!GifWriteFrame(&gif_writer,
im.convertToFormat(QImage::Format_Indexed8).convertToFormat(QImage::Format_RGBA8888).constBits(),
im.convertToFormat(QImage::Format_RGBA8888).constBits(),
static_cast<uint32_t>(im.width()),
static_cast<uint32_t>(im.height()),
static_cast<uint32_t>(frame_delay))) {
@@ -1951,6 +1952,7 @@ void Graphic::on_graphic_buttonRecord_clicked(bool checked) {
}
GifEnd(&gif_writer);
}
qApp->restoreOverrideCursor();
}
record_imgs.clear();
}