We strongly recommend to refer below post as a prerequisite of this.
- Image Processing in Java | Set 1 (Read and Write)
- Image Processing In Java | Set 2 (Get and set Pixels)
In this set we will be converting a colored image to negative image.
Note: In a negative image the Alpha component of the image will be same as the original image, but the RGB will be changed i.e, all three RGB components will be having a value of 255-original component value.
- Get the RGB value of the pixel.
- Calculate new RGB values as follows:
- R = 255 – R
- G = 255 – G
- B = 255 – B
- Replace the R, G and B value of the pixel with the values calculated in step 2.
- Repeat Step 1 to Step 3 for each pixels of the image.
Implementation of the above algorithm:
Note : This code will not run on online IDE as it needs an image on disk.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.