zoukankan      html  css  js  c++  java
  • 注意:MagickReadImageBlob() 引发的问题

    今天发现:

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

    MagickReadImageBlob(mw, data, dataLen)

    程序运行发生了崩溃。

    最后找到原因: MagickReadImageBlob() -> 读取图像或图像序列。 图像仅在当前图像指针位置之前插入。

    可通过下面的代码进行验证:

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

    MagickResetIterator(mw);
    while(MagickHasNextImage(mw))
    {
    printf("MagickNextImage(mw):%d ", MagickNextImage(mw));
    }

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

    看来正确的做法:

    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.

  • 相关阅读:
    Codeforces Global Round 6
    Codeforces Global Round 5
    笔记
    笔记
    Codeforces Round #608 (Div. 2)
    模板
    Codeforces Round #607 (Div. 2)
    find命令
    while循环脚本
    发邮件
  • 原文地址:https://www.cnblogs.com/personnel/p/12076911.html
Copyright © 2011-2022 走看看