warning: unnecessary conversion (unconvert)
This comes from the following line:
offsetY += 60 + image.Image(*img.Bitmap).Bounds().Max.Y
It took me a while to understand how to convert this interface pointer to an interface yet I do not think that this is the right solution since gometalinter raises a warning.
I want to get the width of the img
.
img
is of struct Image
and has a Bitmap pointer to a real image.Image
(image stdlib). If I want to call Bounds
on the actual image.Image
I need to transform the pointer to the interface into an interface.
How should that be done in a more go friendly way?
I have the following go code:
import (
"image"
"image/color"
"image/draw"
)
type Image struct {
Src string
Title string
Width int
Height int
Index int
Bitmap *image.Image
}
type Images []Image
offsetY = 10
func ComposeImage(imgs Images) image.Image {
masterRGBAImg := image.NewRGBA(image.Rect(0, 0, 300, 300))
masterBounds := masterRGBAImg.Bounds()
for _, img := range imgs {
draw.Draw(masterRGBAImg, masterBounds,
*img.Bitmap, image.Point{X: -10, Y: -offsetY + 10}, draw.Src)
addLabel(masterRGBAImg, 10, offsetY-30, img.Title)
// HERE ======
offsetY += 60 + image.Image(*img.Bitmap).Bounds().Max.Y
// END ======
}
return masterRGBAImg
}
// Draw label on image.
func addLabel(img *image.RGBA, x int, y int, label string) {
col := color.RGBA{50, 50, 50, 255}
point := fixed.Point26_6{X: fixed.Int26_6(x * 64), Y: fixed.Int26_6(y * 64)}
d := &font.Drawer{
Dst: img,
Src: image.NewUniform(col),
Face: inconsolata.Bold8x16,
Dot: point,
}
d.DrawString(label)
}