Image Processing in Java – Creating a Random Pixel Image
- Image Processing in Java – Read and Write
- Image Processing In Java – Get and Set Pixels
- Image Processing in Java – Colored Image to Grayscale Image Conversion
- Image Processing in Java – Colored Image to Negative Image Conversion
- Image Processing in Java – Colored to Red Green Blue Image Conversion
- Image Processing in Java – Colored Image to Sepia Image Conversion
In this article, 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.
A random image is an image in which the pixels are chosen at random, so they can take any color from the desired palette (generally 16 million colors). The resulting images look like multi-colored noise backgrounds.
- Set the dimension of the new image file.
- Create a BufferedImage object to hold the image. 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 steps 3 and 4 for each pixel of the image.
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 write.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.