When I call png.Decode(imageFile)
it returns a type image.Image
. But I can't find a documented way to convert this to an image.NRGBA
or image.RGBA
on which I can call methods like At()
.
How can I achieve this?
If you don't need to "convert" the image type, and just want to extract the underlying type from the interface, use a "type assertion":
if img, ok := i.(*image.RGBA); ok {
// img is now an *image.RGBA
}
Or with a type switch:
switch i := i.(type) {
case *image.RGBA:
// i in an *image.RGBA
case *image.NRGBA:
// i in an *image.NRBGA
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With