|
How to set and get the values of pixels in a BufferedImage |
|
|
This Java tip demonstrates how to get and set pixels in a buffered image. The pixels
can be retrieved by using getRGB() function. Further, for setting the pixels setRGB()
function may be used.
// Firstly get a pixel (x.y may be defined by the developer)
int rgb = bufferedImage.getRGB(x, y);
// Developer may get all the pixels
int w = bufferedImage.getWidth(null);
int h = bufferedImage.getHeight(null);
int[] rgbs = new int[w*h];
bufferedImage.getRGB(0, 0, w, h, rgbs, 0, w);
// Secondly set a pixel
rgb = 0xFF00FF00; // green
bufferedImage.setRGB(x, y, rgb);
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.