choose algorithm and don't use gc

This commit is contained in:
Laurent Le Goff 2011-04-14 14:59:35 +02:00
parent f4c15de193
commit 99bb7412b8
1 changed files with 10 additions and 11 deletions

View File

@ -9,6 +9,7 @@ import (
"image" "image"
"time" "time"
"image/png" "image/png"
"exp/draw"
"draw2d.googlecode.com/hg/draw2d" "draw2d.googlecode.com/hg/draw2d"
) )
@ -54,18 +55,16 @@ func loadFromPngFile(filePath string) image.Image {
func main() { func main() {
source := loadFromPngFile("../resource/image/TestAndroid.png") source := loadFromPngFile("../resource/image/TestAndroid.png")
i := image.NewRGBA(1024, 768) dest := image.NewRGBA(1024, 768)
gc := draw2d.NewImageGraphicContext(i) width, height := float64(source.Bounds().Dx()), float64(source.Bounds().Dy())
// gc.Scale(2, 0.5) tr := draw2d.NewIdentityMatrix()
gc.Translate(float64(source.Bounds().Dx()/2), float64(source.Bounds().Dy()/2)) tr.Translate(width/2, height/2)
gc.Rotate(30 * math.Pi / 180) tr.Rotate(30 * math.Pi / 180)
gc.Translate(float64(-source.Bounds().Dx()/2), float64(-source.Bounds().Dy()/2)) tr.Translate(-width/2, -height/2)
gc.Translate(75, 25) tr.Translate(75, 25)
lastTime := time.Nanoseconds() lastTime := time.Nanoseconds()
gc.DrawImage(source) draw2d.DrawImage(source, dest, tr, draw.Over, draw2d.BilinearFilter)
dt := time.Nanoseconds() - lastTime dt := time.Nanoseconds() - lastTime
fmt.Printf("Draw image: %f ms\n", float64(dt)*1e-6) fmt.Printf("Draw image: %f ms\n", float64(dt)*1e-6)
saveToPngFile("../resource/result/TestDrawImage.png", i) saveToPngFile("../resource/result/TestDrawImage.png", dest)
} }