Add InvertMask and an example
This commit is contained in:
parent
0e0ff3ade7
commit
cdabe43353
12
context.go
12
context.go
@ -496,6 +496,18 @@ func (dc *Context) AsMask() *image.Alpha {
|
|||||||
return mask
|
return mask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InvertMask inverts the alpha values in the current clipping mask such that
|
||||||
|
// a fully transparent region becomes fully opaque and vice versa.
|
||||||
|
func (dc *Context) InvertMask() {
|
||||||
|
if dc.mask == nil {
|
||||||
|
dc.mask = image.NewAlpha(dc.im.Bounds())
|
||||||
|
} else {
|
||||||
|
for i, a := range dc.mask.Pix {
|
||||||
|
dc.mask.Pix[i] = 255 - a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clip updates the clipping region by intersecting the current
|
// Clip updates the clipping region by intersecting the current
|
||||||
// clipping region with the current path as it would be filled by dc.Fill().
|
// clipping region with the current path as it would be filled by dc.Fill().
|
||||||
// The path is cleared after this operation.
|
// The path is cleared after this operation.
|
||||||
|
14
examples/invert-mask.go
Normal file
14
examples/invert-mask.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/fogleman/gg"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dc := gg.NewContext(1024, 1024)
|
||||||
|
dc.DrawCircle(512, 512, 384)
|
||||||
|
dc.Clip()
|
||||||
|
dc.InvertMask()
|
||||||
|
dc.DrawRectangle(0, 0, 1024, 1024)
|
||||||
|
dc.SetRGB(0, 0, 0)
|
||||||
|
dc.Fill()
|
||||||
|
dc.SavePNG("out.png")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user