VOOZH about

URL: https://www.geeksforgeeks.org/java/image-processing-in-java-creating-a-mirror-image/

⇱ Image Processing in Java - Creating a Mirror Image - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Image Processing in Java - Creating a Mirror Image

Last Updated : 23 Jul, 2025

Prerequisite: 

In this set, we will be creating a mirror image. The image of an object as seen in a mirror is its mirror reflection or mirror image. In such an image, the object's right side appears on the left side and vice versa. A mirror image is therefore said to be laterally inverted, and the phenomenon is called lateral inversion. The main trick is to get the source pixel values from left to right and set the same in the resulting image from right to left.

Algorithm: 

  1. Read the source image in a BufferedImage to read the given image.
  2. Get the dimensions of the given image.
  3. Create another BufferedImage object of the same dimension to hold the mirror image.
  4. Get ARGB (Alpha, Red, Green, and Blue) values from the source image [in left to right fashion].
  5. Set ARGB (Alpha, Red, Green, and Blue) to newly created image [in the right to left fashion].
  6. Repeat steps 4 and 5 for each pixel of the image.

Implementation: 

Output:

Note: This code will not run on online ide since it requires an image in the drive.

Comment
Article Tags: