[Magick++/ImageCore] Get colorspace attribute from file

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
laurenthnd
Posts: 2
Joined: 2011-02-23T16:57:00-07:00
Authentication code: 8675308
Contact:

[Magick++/ImageCore] Get colorspace attribute from file

Post by laurenthnd »

Hello,

I would like to get some information about an image stored in a file using Magick++ or ImageCore interfaces.
If I do something like:

Code: Select all

Image image("myimage.pgm");
I can get the dimensions using:

Code: Select all

image.rows();
image.height();
However, the colorspace is set by default to RGB, whereas pgm images are always grayscale.

Therefore, my question is: How can I retrieve from the file:
- colorspace
- bit depth
Using Magick++ or ImageCore.

For instance, in the case of a pgm image, it should returns:
- colorspace: GRAYSCALE
- bit depth: A VALUE IN [1,16]

Many thanks in advance.


P.S.:
I know that I can do that using the identify tool in the command line. But how can I make use of the ImageMagick API for this purpose (avoiding the high-level ImageWand interface). I've tried to use the ImageInfo structure of ImageCore without success:

Code: Select all

ExceptionInfo *exception;
Image *image;
ImageInfo *image_info;
// Initialize the image info structure and read an image.
MagickCoreGenesis(*argv,MagickTrue);
exception=AcquireExceptionInfo();
image_info=AcquireImageInfo();
(void) strcpy(image_info->filename,"myimage.pgm");
image=ReadImage(image_info,exception);
// HERE: the image_info structure does not contain the colorspace "corresponding" to the content of the file
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: [Magick++/ImageCore] Get colorspace attribute from file

Post by magick »

Try image.type().
laurenthnd
Posts: 2
Joined: 2011-02-23T16:57:00-07:00
Authentication code: 8675308
Contact:

Re: [Magick++/ImageCore] Get colorspace attribute from file

Post by laurenthnd »

Thanks, this indeed works as the depth() function does.
However, I consider that this is a bit weird. In a certain way, imageType is used for loading while colorSpace is used for saving. Do you know why different enumerations are considered for loading and saving?
Thanks and cheers
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 16 guests