Re: [GD-DEVEL] Polygon with holes
[email protected] (Nathan Vander Wilt)
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sep 12, 2007, at 8:34 PM, Mateusz Loskot wrote: > Hi, > > Could anyone provide me with some tricks about what's the best and > efficiently way to render filled polygon with one or more holes? > IOW, how to render a donut-like polygon that's filled with red colour > but internal ring is not filled (is displayed as transparent). What I ended up doing in a recent project is creating a new paletted image buffer of image size and allocate two colors, black and white. The black is allocated first and fills the background. Then I drew the non-hole parts of the polygon in white, without anti-aliasing. (GD's antialiasing isn't great for polygons with dense vertices anyway.) Then I drew the holes back in black. Once that is done, I iterated over the buffer and whenever I found a white pixel, I set the correct color on the main image's corresponding pixel. Efficient? Maybe not. Simple, yes. hth, –natevw