WriteColorFIle does not seem to work with RGBA values
lcmps opened this issue · 2 comments
I've been doing some tests with this library and it's been great so far, but for some reason whenever I try to generate a QR code with RGBA foreground/background colors the function will create a blank PNG whiteout outputting any errors.
For example:
fg := color.RGBA{0, 0, 0, 1} // black
bg := color.RGBA{0, 0, 0, 0} // white
qrcode.WriteColorFile("dummyData", qrcode.Medium, 300, bg, fg, "colored.png")
Will result in a blank 300x300 png
but doing this:
fg := color.CMYK{0, 0, 0, 100} // black
bg := color.CMYK{0, 0, 0, 0} // white
qrcode.WriteColorFile("dummyData", qrcode.Medium, 300, bg, fg, "colored.png")
Will correctly output a valid QR code and non-blank PNG, passing bg := color.White
and fg := color.Black
as stated in the documentation works too.
Am I doing something wrong with my RGBA values and this behavior is expected or an actual issue with RGBA implementation somewhere in the library?
Cheers
In RGBA, all values are 8 bits (0 <= n <= 255) and the final value in the constructor is the Alpha channel, ie transparency. So the two values you have provided are instead both black but mostly, if not completely, transparent.
color.RGBA{0, 0, 0, 0}
is 100% transparent, and although you are correct that color.RGBA{0, 0, 0, 1}
is black, it is also 99.7% transparent.
True black is color.RGBA{0, 0, 0, 255}
and white is color.RGBA{255, 255, 255, 255}
Thanks for the explanation, you're right. I was thinking of RGBA values in terms of CSS, where the '1' value for Alpha is interpreted as 100% opacity
Thank you