Golang image.Alpha.Opaque function example

package image

 func (p *Alpha) Opaque() bool
  

Opaque scans the entire image and reports whether it is fully opaque.

Golang image.Alpha.Opaque function usage example

 package main

 import (
 "fmt"
 "image"
 "image/draw"
 )

 func main() {
 canvas := image.NewAlpha(image.Rect(0, 0, 100, 100))

 // is this canvas(image) opaque
 op := canvas.Opaque()

 fmt.Println("canvas is opaque ? ", op)

 rgba := image.NewRGBA(image.Rect(0, 0, 100, 100))

 // see http://golang.org/pkg/image/#pkg-variables for image.Opaque 
 draw.Draw(rgba, image.Rect(0, 0, 100, 100), image.Opaque, image.ZP, draw.Src) 

 op1 := rgba.Opaque()

 fmt.Println("rgba is opaque ? ", op1)

 }

Output :

canvas is opaque ? false

rgba is opaque ? true

Reference :

http://golang.org/pkg/image/#Alpha.Opaque

Advertisement