madopal has asked for the wisdom of the Perl Monks concerning the following question:

Ok, so I'm tinkering around with gd, and I have a question about setPixel (this isn't even addressed on the C side).

The setPixel routine assumes an indexed color to be passed (AFAIK), but...if you've declared a truecolor image, do you still have to pass an RGB value to colorClosest or colorExact to get a color index? Even though it's not indexed? Or is there some way to pass an RGB value directly to setPixel?

Thanks!

--
"...if you drink much from a bottle marked 'poison,' it is most certain to disagree with you, sooner or later."
-- Lewis Carroll, Alice's Adventures in Wonderland

Replies are listed 'Best First'.
Re: gd, setpixel, and truecolor
by hossman (Prior) on Sep 17, 2003 at 07:13 UTC

    First off, make sure you've got a version of CD that supports truecolor.

    I still haven't bothered to upgrade, so I have no first hand knowledge of this, but from what I can tell from the C API, you should still use colorClosest.

Re: gd, setpixel, and truecolor
by ant9000 (Monk) on Sep 17, 2003 at 07:10 UTC
    You can't declare a truecolor image in GD, AFAIK; you have just created a GD/GD2 in memory internal representation of your original truecolor image file. This representation is indexed - at least, it appears to be so from the docs, never read the actual code myself - thus the need for color allocation. On output, the representation is converted to whatever format you need, truecolor or not.