Creating a Gif using ImageMagick 6.9.7.4.
I convert a vector of QImage
, to ImageMagick
image type and create a gif using the static method. But resulted gif is so fast, how can set I an interval between frames, or make by gif some slow?
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";
and QImage
to 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;
}
CodePudding user response:
Image img1( "100x100", "white" );
img1.pixelColor( 49, 49, "red" );
frames.push_back(img1);
Image img2( "100x100", "red" );
img2.pixelColor( 49, 49, "white" );
frames.push_back(img2);
img1.animationDelay(2000);
img2.animationDelay(2000);*/
Magick::writeImages(frames.begin(), frames.end(), "f:\\2.gif");
Sure, you should set an animationDelay
property in Magick::Image
object