Image Processing in Java | Set 7 (Creating a random pixel image)
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.
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.