LoadImage
This commit is contained in:
parent
64d88fe46a
commit
9d56681560
@ -167,6 +167,7 @@ Sometimes you just don't want to write these yourself.
|
|||||||
```go
|
```go
|
||||||
Radians(degrees float64) float64
|
Radians(degrees float64) float64
|
||||||
Degrees(radians float64) float64
|
Degrees(radians float64) float64
|
||||||
|
LoadImage(path string) (image.Image, error)
|
||||||
LoadPNG(path string) (image.Image, error)
|
LoadPNG(path string) (image.Image, error)
|
||||||
SavePNG(path string, im image.Image) error
|
SavePNG(path string, im image.Image) error
|
||||||
```
|
```
|
||||||
|
@ -13,7 +13,7 @@ func main() {
|
|||||||
dc.Fill()
|
dc.Fill()
|
||||||
dc.Pop()
|
dc.Pop()
|
||||||
}
|
}
|
||||||
if im, err := gg.LoadPNG("examples/gopher.png"); err == nil {
|
if im, err := gg.LoadImage("examples/gopher.png"); err == nil {
|
||||||
dc.DrawImageAnchored(im, S/2, S/2, 0.5, 0.5)
|
dc.DrawImageAnchored(im, S/2, S/2, 0.5, 0.5)
|
||||||
}
|
}
|
||||||
dc.SavePNG("out.png")
|
dc.SavePNG("out.png")
|
||||||
|
10
util.go
10
util.go
@ -24,6 +24,16 @@ func Degrees(radians float64) float64 {
|
|||||||
return radians * 180 / math.Pi
|
return radians * 180 / math.Pi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadImage(path string) (image.Image, error) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
im, _, err := image.Decode(file)
|
||||||
|
return im, err
|
||||||
|
}
|
||||||
|
|
||||||
func LoadPNG(path string) (image.Image, error) {
|
func LoadPNG(path string) (image.Image, error) {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user