Use the Color
constuctor that takes two arguments:
Color pixelVal = new Color(original.getRGB(x, y), true);
This constructor creates a Color
with an ARGB color, if the hasAlpha
parameter is true
.
The single argument constructor Color(int)
does not take transparency into account. From the JavaDoc:
Creates an opaque sRGB color with the specified combined RGB value [...] Alpha is defaulted to 255.
Apart from that, your code should probably work. :-)