fix bug in PictureDataFromImage

This commit is contained in:
faiface 2017-03-01 12:34:30 +01:00
parent 0644103ba1
commit b1311c29b6
1 changed files with 7 additions and 5 deletions

12
data.go
View File

@ -160,11 +160,13 @@ func verticalFlip(nrgba *image.NRGBA) {
//
// The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds.
func PictureDataFromImage(img image.Image) PictureData {
nrgba := image.NewNRGBA(image.Rect(
0, 0,
img.Bounds().Dx(), img.Bounds().Dy(),
))
draw.Draw(nrgba, nrgba.Bounds(), img, img.Bounds().Min, draw.Src)
var nrgba *image.NRGBA
if img, ok := img.(*image.NRGBA); ok {
nrgba = img
} else {
nrgba = image.NewNRGBA(img.Bounds())
draw.Draw(nrgba, nrgba.Bounds(), img, img.Bounds().Min, draw.Src)
}
verticalFlip(nrgba)