首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C的MagickWand,调用DestroyPixelWands时出错

C的MagickWand,调用DestroyPixelWands时出错
EN

Stack Overflow用户
提问于 2011-09-02 07:58:03
回答 2查看 442关注 0票数 0

我开始在一个简单的C程序中使用ImageMagick和MagickWand应用程序接口。现在,作为测试,我只是在帧中寻找黑色像素。下面是我的代码:

代码语言:javascript
复制
int find_black_pixel(MagickWand *wand) {
    int res = 0;
    PixelIterator * iterator = NewPixelIterator(wand);
    size_t width=MagickGetImageWidth(wand);
    size_t height=MagickGetImageHeight(wand);
    PixelWand ** pixels;
    unsigned long x,y;
    unsigned int alpha;
    unsigned int red, green, blue;

    //printf("Width : %d, Height : %d\n", (int)width, (int)height);

    for (y=0; y<height; y++) {
        pixels = PixelGetNextIteratorRow(iterator, &width);
        for (x=0; x<width; x++) {

            alpha = (unsigned int) (255*PixelGetAlpha(pixels[x]));
            if (alpha == 0)
                continue;

            red = (unsigned int) (255*PixelGetRed(pixels[x]));
            green = (unsigned int) (255*PixelGetGreen(pixels[x]));
            blue = (unsigned int) (255*PixelGetBlue(pixels[x]));

            //printf("At %04ld,%04ld, alpha : %d, rgb : %d,%d,%d\n", x,y,alpha, red, green, blue);

            if ((red ==0) || (green == 0) || (blue ==0)) {

                res = 1;
                //DestroyPixelWands(pixels, width);
                goto finished_find_black_pixel;
            }

        }
        //DestroyPixelWands(pixels, (size_t)width);
    }

finished_find_black_pixel:
    DestroyPixelIterator(iterator);

    return res;
}

如果我取消注释任何DestroyPixelWands调用,我会得到一个断言:

代码语言:javascript
复制
test: wand/pixel-wand.c:283: DestroyPixelWands: Assertion `(*wand)->signature == 0xabacadabUL' failed.

你知道为什么会发生这种事吗?

编辑:

更多调试...即使调用DestroyPixelWand(pixels[0]);也会以同样的方式失败...

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-02 08:12:42

我怀疑pixels不是一个单独的可销毁对象(它只是一个指向原始wand对象的指针),而且您当前的代码没有任何销毁pixels的代码。

票数 0
EN

Stack Overflow用户

发布于 2011-09-07 02:06:50

从ImageMagick forum那里得到了答案:

当与像素迭代器关联时,像素棒是私有的。当您销毁像素迭代器时,像素棒将被销毁。不要对像素迭代器使用DestroyPixelWands()。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7277954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档