```val bb = terrain!![posRed + 1] and 0xff.toByte(...
# getting-started
h
Copy code
val bb = terrain!![posRed + 1] and 0xff.toByte()
val gg = terrain[posRed + 2] and 0xff.toByte()
val rr = terrain[posRed + 3] and 0xff.toByte()
g.color = Color(rr.toInt(), gg.toInt(), bb.toInt())
i
Here you have
bb
,
gg
and
rr
still having
Byte
type and that type is signed: it ranges from -128 to 127. The negative values are outside of the color component range when you convert them to int.
h
so what is your suggestion? convert the byte to Int instead of the Int to Byte?
i
try
Copy code
val rr = terrain[posRed + 1].toInt() and 0xFF
...
g.color = Color(rr, gg, bb)
h
gotcha
thanks
v
Interesting, but infix
Byte and Byte
did not work for me, while
Byte.and(Byte)
did. Anyway constructor
Color(Byte, Byte, Byte)
was not found