Page 1 of 1

pixels argument of MagickGetImagePixels()

Posted: 2008-02-24T15:04:15-07:00
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?

Re: pixels argument of MagickGetImagePixels()

Posted: 2008-02-25T00:27:44-07:00
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?

Re: pixels argument of MagickGetImagePixels()

Posted: 2008-02-25T07:12:55-07:00
by magick
Why not try CharPixel instead of IntegerPixel. CharPixel has a range of 0 .. 255 for each pixel component.