Example #1
0
func main() {
	file, err := os.Open("android.png")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	a, _, err := image.Decode(file)

	//load go icon image
	file2, err := os.Open("go.png")
	if err != nil {
		log.Fatal(err)
	}
	defer file2.Close()
	g, _, err := image.Decode(file2)

	if err != nil {
		log.Fatal(err)
	}

	ar := a.Bounds()
	w, h, x := ar.Dx(), ar.Dy(), 30.0
	i := image.NewRGBA(image.Rect(0, 0, w, h))
	draw.Draw(i, ar, a, ar.Min, draw.Src)

	tr := draw2d.NewRotationMatrix(x * (math.Pi / 180.0))
	draw2d.DrawImage(g, i, tr, draw.Over, draw2d.LinearFilter)
	saveToPngFile("Test2.png", i)
}
func rotate(interpreter *Interpreter) {
	value := interpreter.Pop()
	matrix, ok := value.(draw2d.MatrixTransform)
	var angle float64
	if !ok {
		matrix = interpreter.GetGraphicContext().GetMatrixTransform()
		angle = value.(float64) * math.Pi / 180
	} else {
		angle = interpreter.PopFloat() * math.Pi / 180
	}
	if !ok {
		interpreter.GetGraphicContext().Rotate(angle)
	} else {
		matrix = draw2d.NewRotationMatrix(angle).Multiply(matrix)
		interpreter.Push(matrix)
	}
}