注意:MagickReadImageBlob() 引发的问题

今天发现:

如果之前的 mw 已加载了具体的图片数据后,再对这个 mw 进行:

MagickReadImageBlob(mw, data, dataLen)

程序运行就会出现异常,估计是内存出了问题。

--------------------------------------------------------------

看来正确的做法:

mw = NewMagickWand();
MagickReadImageBlob(mw, data, dataLen);

或:

ClearMagickWand(mw); //先清除之前的

MagickReadImageBlob(mw, data, dataLen);

---------------------------------------------------------------

一切的根源在于: 

https://imagemagick.org/api/magick-image.php#MagickReadImageBlob

MagickReadImageBlob(): reads an image or image sequence from a blob. In all other respects it is like MagickReadImage().

https://imagemagick.org/api/magick-image.php#MagickReadImage

MagickReadImage():

MagickReadImage() reads an image or image sequence. The images are inserted jjust before the current image pointer position.

Use MagickSetFirstIterator(), to insert new images before all the current images in the wand, MagickSetLastIterator() to append add to the end, MagickSetIteratorIndex() to place images just after the given index.

MagickReadImage()读取图像或图像序列。 图像仅在当前图像指针位置之前插入。

使用MagickSetFirstIterator()将新图像插入到魔杖中的所有当前图像之前,将MagickSetLastIterator()附加到末尾,然后将MagickSetIteratorIndex()插入到给定索引之后。

https://imagemagick.org/api/magick-wand.php#ClearMagickWand

ClearMagickWand() clears resources associated with the wand, leaving the wand blank, and ready to be used for a new set of images.

猜你喜欢

转载自www.cnblogs.com/personnel/p/12076911.html