Problem filling an image
[email protected] (Brian Peschel) Thu, 06 Nov 2008 14:35:10 -0600
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
I have some class that generates an image through GD. I new the class
for each image I create and I create thousand of images in the life of
the program. I have a problem where the background color is a random
color if I set the background color to black (RGB 0,0,0). It works if I
set it to just about anything else (grey RGB 190,190,190 or linen
250,240,230). The actual fill color is black on the first image I
generate (in the lifetime), then it will go random. I have seen green,
blue, red, purple, etc. I assume this is a problem with GD, as it works
with every other color I have tried except black.
Here is the code I am using.
gdImagePtr _image;
int _line_color;
int style[20];
_image = gdImageCreateTrueColor(xPixels, yPixels);
// Allocate the first color
gdImageColorAllocate(_image, backgroundColor.red(),
backgroundColor.green(), backgroundColor.blue());
// Fill the background
_line_color = gdImageColorAllocate(_image, backgroundColor.red(),
backgroundColor.green(), backgroundColor.blue());
gdImageSetThickness(_image, 1);
style[0] = _line_color;
gdImageSetStyle(_image, style, 1);
gdPoint* points = new gdPoint[4];
points[0].x = xPixels;
points[0].y = 0;
points[1].x = xPixels;
points[1].y = yPixels;
points[2].x = 0;
points[2].y = yPixels;
points[3].x = 0;
points[3].y = 0;
gdImageFilledPolygon(_image, points, 4, _line_color);
delete[] points;
Then I do all my other drawing. I have tried it with and without the
first color allocation (the 'Allocate the first color') which I needed
when I was creating the image with gdImageCreate() which set the
background color for me (and I didn't need to explicitly fill the
background).
Any thoughts?
- Brian