fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.34k stars 352 forks source link

Draw a shape with empty space inside. #182

Closed kwinso closed 1 year ago

kwinso commented 1 year ago

I'm trying to draw a rectangle that has empty space in it for QR code finders (big squares in corners of a qr code). It should look like this:

IMG_20230128_141801_056.jpg

I'm trying to draw another smaller rectangle inside with transparent color, but it changes nothing.

I need a "hole" to be of transparent color, as the finder will be placed on top of background with variable color (maybe even gradient)

Solutions tried:

Any suggestions on this problem? Thanks in advance! 🙏

kwinso commented 1 year ago

The solution was to use dc.SetFillRuleEvenOdd(). There's no docs on this, but I assume this will clear filled region if you call Fill on this region.

image

Note: placeFinderShapes will just place 3 shapes without filling it. Basically, it calls DrawRoundedRectangle under the hood.