Page 1 of 1

MagickGetSize always returns 0 height and 0 length

Posted: 2007-01-01T06:18:52-07:00
by Bary
Hey,
I wanna use MagickGetSize to get the size in pixels of an image in a wand, but the rows and the columns are every time zero.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>
#include <unistd.h>

int main()
{
        long colls, rows;

        MagickWand *wand;

        MagickWandGenesis();

        wand = NewMagickWand();
        MagickReadImage(wand, "test.jpg");
        MagickGetSize(wand, &colls, &rows);
        printf("columns: %ld rows: %ld\n", colls, rows);

        MagickWandTerminus();

        _exit(0);
}
The output is only: columns: 0 rows: 0


Thx in advance,
Bary

Posted: 2007-01-01T08:11:51-07:00
by magick
A common mistake that MagickWand and PerlMagick users makes is to assume that all calls to the API were successful. Add checks for success and display the exception if the method fails. For example,

Code: Select all

    status=MagickReadImage(magick_wand,"image.gif");
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
where ThrowWandException () is

Code: Select all

  #define ThrowWandException(wand) \
  { \
    char \
      *description; \
   \
    ExceptionType \
      severity; \
   \
    description=MagickGetException(wand,&severity); \
    (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \
    description=(char *) MagickRelinquishMemory(description); \
    exit(-1); \
  }

The functions are working properly

Posted: 2007-01-01T13:23:49-07:00
by Bary
Thanks for your very fast answer, but this isn't the problem. There aren't any errors by the functions (and so ThrowWandException doesn't report any).


I also saved the read image at an other file name and this worked correctly, so the image is read as expected.


greetings

Posted: 2007-01-01T13:38:05-07:00
by magick
Ok, try
  • printf("columns: %ld rows: %ld\n", MagickGetImageWidth(wand),
    MagickGetImageHeight(wand));
The image size is a setting for raw image formats that do not include the size in the file headers such as raw red, green, blue image files.

It works

Posted: 2007-01-01T14:40:13-07:00
by Bary
Okay that works.

Thx