Created
February 21, 2020 06:39
-
-
Save parzibyte/d678012b6271660cf445f256a073c779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
____ _____ _ _ _ | |
| _ \ | __ \ (_) | | | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___ | |
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \ | |
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/ | |
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___| | |
__/ | __/ | | |
|___/ |___/ | |
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