Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 21, 2020 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d678012b6271660cf445f256a073c779 to your computer and use it in GitHub Desktop.
Save parzibyte/d678012b6271660cf445f256a073c779 to your computer and use it in GitHub Desktop.
/*
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
Copyright (c) 2020 Luis Cabrera Benito
Licenciado bajo la licencia MIT
El texto de arriba debe ser incluido en cualquier redistribución
*/
func convertirBitMatrixAImagen(anchura, altura int, bitMatrix *gozxing.BitMatrix) (string, error) {
esquinaSuperiorIzquierda := image.Point{0, 0}
esquinaInferiorDerecha := image.Point{X: anchura, Y: altura}
imagen := image.NewRGBA(image.Rectangle{Min: esquinaSuperiorIzquierda, Max: esquinaInferiorDerecha})
blanco := color.RGBA{R: 255, G: 255, B: 255, A: 0xff}
negro := color.RGBA{0, 0, 0, 0xff}
for x := 0; x < anchura; x++ {
for y := 0; y < altura; y++ {
valor := bitMatrix.Get(x, y)
if valor {
imagen.Set(x, y, negro)
} else {
imagen.Set(x, y, blanco)
}
}
}
nombreImagen := "imagen.png"
archivoImagen, err := os.Create(nombreImagen)
defer archivoImagen.Close()
if err != nil {
return "", err
}
err = png.Encode(archivoImagen, imagen)
return nombreImagen, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment