Closed cospotato closed 5 years ago
OK, now this code working.
package main
import (
"log"
"github.com/fogleman/gg"
)
func main() {
im, err := gg.LoadImage("examples/lenna.png")
if err != nil {
log.Fatal(err)
}
// Draw image1
dc := gg.NewContext(1024, 1024)
tmpDc1 := gg.NewContext(512, 512)
tmpDc1.DrawRoundedRectangle(0, 0, 512, 512, 64)
tmpDc1.Clip()
tmpDc1.DrawImage(im, 0, 0)
dc.DrawImage(tmpDc1.Image(), 0, 0)
// Draw image2
tmpDc2 := gg.NewContext(512, 512)
tmpDc2.DrawRoundedRectangle(0, 0, 512, 512, 64)
tmpDc2.Clip()
tmpDc2.DrawImage(im, 0, 0)
dc.DrawImage(tmpDc2.Image(), 512, 512)
dc.SavePNG("out.png")
}
Any best practice ?
@Cospotato You can use ResetClip
to clear the clipping region before setting a new one.
@fogleman Thank you for your reply!
I have another question: How to DrawImage
with transparent mask ?
Firstly, thank you for the great work, it is helpful on drawing with Golang!
Code
Image
Wish
Best Wishes, CosPotato