Creating/reusing wands and images

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
grepnold
Posts: 2
Joined: 2014-12-08T10:32:40-07:00
Authentication code: 6789

Creating/reusing wands and images

Post by grepnold »

Hi all, I'm just starting to use MagickWand's C API. I'm using it for testing some low-level pixel-level operations. I use MagickWand to open a file, I export the pixels into my own malloc'd array, mess around with it a bit and import the array back into the same image and wand. Then when I write the wand's image back to a new file, it's segfaulting on me in a malloc.

I'm not really asking for advice on that problem, for one thing I don't have the details to hand, but I see from el_supremo's useful examples that he uses multiple images per wand, and multiple wands. So the question I have at this stage, because I haven't seen it discussed anywhere, is: When should/must you create new images or wands, and when can you reuse them. Maybe it's simply not valid to change an exported pixel array and import it back?

Sorry for vagueness at this stage, don't have the details to hand but will respond to any requests for more detail.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Creating/reusing wands and images

Post by snibgo »

I can't be specific without seeing code, and I use only MagickCore "image" and not MagickWand "wand" (see my examples at http://im.snibgo.com/customim.htm ), but perhaps you are referencing malloced memory outside of the scope in which you defined it.

How are you doing the export to your array, and import? If you are using supported mechanisms, it should work fine. If you are using faster shortcuts, that might be the problem.
snibgo's IM pages: im.snibgo.com
grepnold
Posts: 2
Joined: 2014-12-08T10:32:40-07:00
Authentication code: 6789

Re: Creating/reusing wands and images

Post by grepnold »

Thanks snibgo. I've now proved that I can change pixels in the array and write it back, so I'm not doing something wrong with MagickWand. My code must be corrupting something.
Post Reply