ebitenutil: added NewImageFromReader(io.Reader) (#1735)

This commit is contained in:
Johnny 2021-07-28 18:34:35 +01:00 committed by GitHub
parent e5254482fe
commit 52df607413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ package ebitenutil
import (
"image"
"io"
"github.com/hajimehoshi/ebiten/v2"
)
@ -42,7 +43,15 @@ func NewImageFromFile(path string) (*ebiten.Image, image.Image, error) {
defer func() {
_ = file.Close()
}()
img, _, err := image.Decode(file)
return NewImageFromReader(file)
}
// NewImageFromReader loads from the io.Reader and returns ebiten.Image and image.Image.
//
// Image decoders must be imported when using NewImageFromReader. For example,
// if you want to load a PNG image, you'd need to add `_ "image/png"` to the import section.
func NewImageFromReader(reader io.Reader) (*ebiten.Image, image.Image, error) {
img, _, err := image.Decode(reader)
if err != nil {
return nil, nil, err
}