problems about Magick::Image API

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
archer

problems about Magick::Image API

Post by archer »

I want to use ImageMagick only for decoding or encoding images of various formats, however, I am not sure how to access the matrix of pixels efficiently from an Image instance.
1. How to create an empty Image instance of some size, which will be used to hold a matrix of pixels later
2. How to import image data into an Image instance from a matrix, which has 0-3 bytes complement at the end of each row
3. How to export image data from an Image instance into a matrix?
archer

Re: problems about Magick::Image API

Post by archer »

I just want to use ImageMagick to read images files of various compression from disk, or to decode raw image data holden in memory buffers (may be similar with the Magick::Blob), and then get the image pixels for some image analysis task,
So is there any way easily to do that?
I have tried 'GetImagePixels' and 'SyncImagePixels' , unluckily, no header file seems to have stated them,
Even if the two functions above can do that, they still seems awkward.
So is there some easier way to fast transfer image pixels after decoded between the Image instance and user image matrix ?

:(
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: problems about Magick::Image API

Post by magick »

Clarify which interface do you want to use: MagickCore, MagickWand, Magick++, PerlMagick, something else?
archer

Re: problems about Magick::Image API

Post by archer »

I used Magick++.
Here is the code:

#include<Magick++.h>

{
Magick::Blob blob(pBuf, nBufSize); //pBuf is a memory buffer holding the raw image data not yet decoded.
Magick::Image img;
try
{
img.read(blob);
}
catch (std::exception &)
{
return -1;
}

//now the "img" hold the pixel data after decoded? how to export the pixel data quickly into a matirx ?

}

On the other hand, when I want to encode an image matrix with "JPEG" format into a memory buffer,
how can I import the pixel data into the "img" (an instance of class Magick::Image) from an image matrix?
and what shoud be after that, is it like this:

{
Magick::Image img;
// what shoud be done to initialize the "img"? and how to import the pixel data from an image matrix into the "img" ?

Magick::Blob blob;
try
{
img.write(&blob, "JPEG");
}
catch (std::exception &)
{

}
memcpy(pBuf, blob.data(), blob.length());
}


I didn't know the how the class Magick::Image manages their internal memory stroage, why not provide with some API to direct access the data of the class Magick::Image, such as "data()" ?

Thanks!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: problems about Magick::Image API

Post by magick »

Have you looked at http://www.imagemagick.org/Magick++/Pixels.html? It discusses the low-level pixel methods. You also write to raw formats such as RGBA to create a linear array of pixels (width x height).
kh263

Re: problems about Magick::Image API

Post by kh263 »

This topic has been useful. Thanks all. By the way, what's the value of the try...catch in the code?
kh263

Re: problems about Magick::Image API

Post by kh263 »

archer,

did the code work for you? if not, can you show me the code that did work?

thanks
Post Reply