package main
import (
"fmt"
"image"
"image/png"
"log"
"os"
)
func main() {
file, err := os.Open("C:\\Users\\wg\\go\\src\\学习go语言\\预处理\\家人们_aa.png")
if err != nil {
log.Fatal(err)
}
dst:="laker.png"
fOut, _ := os.Create(dst)
defer fOut.Close()
// decode jpeg into image.Image
m, err := png.Decode(file)//jpg和png的格式不一样
if err != nil {
log.Fatal(err)
}
defer file.Close()
rotate90 := image.NewRGBA(image.Rect(0, 0, m.Bounds().Dy(), m.Bounds().Dx()))
for x := m.Bounds().Min.Y; x < m.Bounds().Max.Y; x++ {
for y := m.Bounds().Max.X - 1; y >= m.Bounds().Min.X; y-- {
rotate90.Set(m.Bounds().Max.Y-x, y, m.At(y, x))
}
}
/*
rotate180 := image.NewRGBA(image.Rect(0, 0, m.Bounds().Dx(), m.Bounds().Dy()))//旋转180度
for x := m.Bounds().Min.X; x < m.Bounds().Max.X; x++ {
for y := m.Bounds().Min.Y; y < m.Bounds().Max.Y; y++ {
rotate180.Set(m.Bounds().Max.X-x, m.Bounds().Max.Y-y, m.At(x, y))
}
}
旋转270度
rotate270 := image.NewRGBA(image.Rect(0, 0, imgb.Bounds().Dy(), imgb.Bounds().Dx()))
for x := imgb.Min.Y; x < imgb.Max.Y; x++ {
for y := imgb.Max.X - 1; y >= imgb.Min.X; y-- {
rotate270.Set(x, imgb.Max.X-y, imgDec.At(y, x))
}
}
*/
png.Encode(fOut,rotate90)
fmt.Println("旋转成功,保存为某某rotate")
}
06-28
1105
05-26
03-31
567
09-17
224