issue23
This commit is contained in:
parent
f7dc650faa
commit
fb2948a31e
4 changed files with 64 additions and 0 deletions
BIN
issue23/Test2.png
Normal file
BIN
issue23/Test2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
issue23/android.png
Normal file
BIN
issue23/android.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
issue23/go.png
Normal file
BIN
issue23/go.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
64
issue23/issue23.go
Normal file
64
issue23/issue23.go
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"code.google.com/p/draw2d/draw2d"
|
||||||
|
"image"
|
||||||
|
"image/draw"
|
||||||
|
"image/png"
|
||||||
|
"math"
|
||||||
|
)
|
||||||
|
|
||||||
|
func saveToPngFile(filePath string, m image.Image) {
|
||||||
|
f, err := os.Create(filePath)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
b := bufio.NewWriter(f)
|
||||||
|
err = png.Encode(b, m)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
err = b.Flush()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Wrote %s OK.\n", filePath)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
Loading…
Reference in a new issue