使用ImageMagick 6.9.7.4创建Gif。
我将 QImage 的向量转换为 ImageMagick 图像类型,并使用静态方法创建一个gif。但是结果是gif这么快,怎么能在帧之间设置一个间隔,或者由gif使一些慢呢?
QImage
ImageMagick
std::vector<Magick::Image> listOfImages; for (QImage &image:m_listOfImages) qDebug()<< image.size(); listOfImages.push_back(QImageToImage(image)); qDebug()<< listOfImages.size(); QString gifName=QDateTime::currentDateTime().toString(QStringLiteral("hh-mm-ss"))+".gif"; Magick::writeImages(listOfImages.begin(), listOfImages.end(), gifName.toStdString()); qDebug()<< "Done";
和 QImage 到 Magick::Image
Magick::Image
Magick::Image DspPresenter::QImageToImage(QImage &qimage) qDebug() << "toImage:" << qimage.width() << qimage.height(); const Magick::Geometry geometry(qimage.width(), qimage.height()); const Magick::ColorRGB color(0.5, 0.2, 0.3); Magick::Image newImage(geometry, color); double scale = 1 / 256.0; newImage.modifyImage(); Magick::PixelPacket *pixels; Magick::ColorRGB mgc; for (int y = 0; y < qimage.height(); ++y) pixels = newImage.setPixels(0, y, newImage.columns(), 1); for (int x = 0; x < qimage.width(); ++x) QColor pix = qimage.pixel(x, y); mgc.red(scale *pix.red()); mgc.green(scale *pix.green()); mgc.blue(scale *pix.blue()); *pixels++ = mgc; newImage.syncPixels(); return newImage; }
618夏日盛惠
2核2G云服务器首年95元,GPU云服务器低至9.93元/天,还有更多云产品低至0.1折…
Image img1( "100x100", "white" ); img1.pixelColor( 49, 49, "red" ); frames.push_back(img1); Image img2( "100x100", "red" ); img2.pixelColor( 49, 49, "white" );