Image Processing in Java | Set 8 (Creating mirror 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 mirror image.
The main trick is to just get the source pixel values from left to right and set the same in the result image from right to left.
- Read the source image in a BufferedImage to read the given image.
- Get the dimensions of the given image.
- Create another BufferedImage object of same dimension to hold the mirror image.
- Get ARGB (Alpha, Red, Green and Blue) values from source image [in left to right fashion].
- Set ARGB (Alpha, Red, Green and Blue) to newly created image [in right to left fashion].
- Repeat the steps 4 and 5 for each pixels of the image.
Below is Java implementation of above steps.
NOTE:Code will not run on online ide since it requires 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 email@example.com. 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.