I'm working with
BufferedImage (in PNG) and want to replace a colour with another. I have all colours stored as strings for easy handling but...
the resultant integers should be negative numbers, but it throws
when I do
output.getRGB(x,y) it returns negative numbers on non-transparent pixels
Best How To :
Values greater that
0x7fff_ffff are too large to be handled as signed
ints. Java 8 has added methods for dealing with
ints as if they contained unsigned values. Simply replace
If you need to work with Java 7 and earlier, you can parse it as a
long and then cast it to
int. Or, if the values are constants, you can write them as numeric constants such as
0xffaaaaaa or even
0xffaa_aaaa and avoid dealing with string conversions (the underscores in numbers are allowed since Java 7 and can make them much easier to read).