如何使用ImageMagick Magick 将图像作为gif写为blob

how to write images as gif to blob using imagemagick Magick++

本文关键字:gif 写为 blob 图像 何使用 ImageMagick Magick      更新时间:2023-10-16
  vector<Magick::Image> frames;
int delay = 20;
for(auto iter=taskList.begin(); iter != taskList.end(); ++iter){
/* hide some codes here*/
  frames.push_back(*img);
}
// write images to file, works fine
Magick::writeImages(frames.begin(), frames.end(), "xxx.gif");
Magick::Blob tmpBlob;
// write images to blob, I then decode the data in blob,  
// and write this blob to yyy.gif. The gif file only contains the first frame image.
Magick::writeImages(frames.begin(), frames.end(), &tmpBlob, true);
// the length is far too small 
LOG_DEBUG("blob data length: %d", tmpBlob.length());
// read from the blob into a imagelist, and print the size of the list
// the size is 1 
vector<Magick::Image> image_list;
Magick::readImages(&image_list, tmpBlob);
LOG_DEBUG("new frames length: %d", image_list.size());

嗨,当我尝试用ImageMagick(版本7.0.3(magick stl.h WriteMages函数写入图像列表时,我有问题。它无法正常工作,似乎只写了一个框架。但是有了相同的图像列表,将它们写入GIF文件的工作正常。有人可以帮我吗?

解决了问题。我失败的原因是我没有做img-> magick(" gif"(,这导致写作不正确。