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 creating a random pixel image. For creating a random pixel image, we don’t need any input image We can create an image file and set its pixel values generated randomly.
- Set the dimension of new image file.
- Create a BufferedImage object to hold the image [ import java.awt.image.BufferedImage; ]. This object is used to store an image in RAM.
- Generate random number values for alpha, red, green and blue components.
- Set the randomly generated ARGB (Alpha, Red, Green and Blue) values.
- Repeat the steps 3 and 4 for each pixels of the image.
Implementation of the above algorithm:
Note : Code will not run on online ide since it writes image in drive.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.