4

I want to change the value of the pixels in an image, for which i need to store the image as a matrix. How can i perform this job? Please guide.

3 Answers 3

6
BufferedImage image = ImageIO.read(..); image.setRGB(x, y, rgb); 

Check the documentation of BufferedImage

Sign up to request clarification or add additional context in comments.

Comments

0

Firstly read the image into a BufferedImage.

BufferedImage image = ImageIO.read(new File("...")); 

Then create matrix like structure in the 2D array like this and set RGB:

for(int i = 0; i < image.getWidth(); i++){ for(int j = 0; j < image.getHeight(); j++){ image.setRGB(i, j, rgb); } } 

Comments

0
  • Image is 2d representation of data (pixel info)

  • 2D means x&y directions. In case of image, these directions are generally treated as rows & columns

  • To change the pixel value, we have to get its location in these rows and columns

  • Getting pixel location is like that class teacher addressing the unknown student with his sitting position (ex:2nd bench 3rd person)

  • Like this we have to address the pixel by its rows and column location

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.