image - How to obtain the red, green and blue values from gray value in java? -
i obtain gray value of pixel :
val=img.getrgb(j, i) & 0xff;
for processing purpose.
now , after processing want red, green , blue values back. how do this?
here sample code obtain r, g, b, alpha, , gray-scale values pixel @ coordinates (x, y) on bufferedimage
.
bufferedimage image; // assume have image int rgb = image.getrgb(x, y); // desired pixel int r = (rgb >> 16) & 0xff; int g = (rgb >> 8) & 0xff; int b = (rgb & 0xff); int alpha = (rgb >> 24) & 0xff; int gray = (r + g + b) / 3; // rgb not affected
Comments
Post a Comment