pixels argument of MagickGetImagePixels()

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
technoinside

pixels argument of MagickGetImagePixels()

Post by technoinside »

Hi,

I´m using PascalMagick port of ImageMagick but i can´t get MagickGetImagePixels to work. I think the problem is exactly on the last argument. How exactly the array dimensions should be?
I´m calling the function this way:

Code: Select all

MagickGetImagePixels(Image,0,0,MagickGetImageWidth(Image),MagickGetImageHeight(Image),'RGB',IntegerPixel,DadosPixels)
In delphi, DadosPixels is defined like Array of Array of Intenger. This way, I defined length of array using: MagickGetImageWidth(Image) * MagickGetImageHeight(Image) and then I was trying to access this way, for example:

DadosPixels[PixelNumber1][R] = pixeldatahere
DadosPixels[PixelNumber1][G] = pixeldatahere
DadosPixels[PixelNumber1] = pixeldatahere
DadosPixels[PixelNumber2][R] = pixeldatahere
DadosPixels[PixelNumber2][G] = pixeldatahere
DadosPixels[PixelNumber2] = pixeldatahere

What´s the correct way to define array dimensions and lenght?
technoinside

Re: pixels argument of MagickGetImagePixels()

Post by technoinside »

Ok. Problem solved using array with only one dimension.

Now i have another problem: the array is being filled with weird (at least for me) values!

White pixel is returning: R-1 G-1 B-1 (negative 1) and sometimes R0 G0 B0 (yes, white pixel)
Black pixel is returning: R0 G0 B0
Blue (#0000FF) pixel is returning: R16843009 G16908287 B-65279

Is there anything wrong with delphi interface to ImageMagick or maybe there is any other method of getting correct values (0-255) of pixel colors? I remember of using the formula "$rgb = floor($red%256 + ($green%256) *256 + ($blue%256) * 256 * 256);" to get integer color for working with Microsoft Word's colors, but seems that inverse formula in this case gives wrong values too.

Tried to use PixelGetColorAsString() but in my case this is a lot slower.

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

Re: pixels argument of MagickGetImagePixels()

Post by magick »

Why not try CharPixel instead of IntegerPixel. CharPixel has a range of 0 .. 255 for each pixel component.
Post Reply