Image Processing in Java - Creating a Mirror Image Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report Prerequisite: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image ConversionImage Processing in Java - Colored Image to Sepia Image ConversionImage Processing in Java - Creating a Random Pixel Image 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: Read the source image in a BufferedImage to read the given image.Get the dimensions of the given image.Create another BufferedImage object of the same dimension to hold the mirror image.Get ARGB (Alpha, Red, Green, and Blue) values from the source image [in left to right fashion].Set ARGB (Alpha, Red, Green, and Blue) to newly created image [in the right to left fashion].Repeat steps 4 and 5 for each pixel of the image.Implementation: Java // Java program to demonstrate // creation of a mirror image import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class MirrorImage { public static void main(String args[]) throws IOException { // BufferedImage for source image BufferedImage simg = null; // File object File f = null; // Read source image file try { f = new File( "C:/Users/hp/Desktop/Image Processing in Java/gfg-logo.png"); simg = ImageIO.read(f); } catch (IOException e) { System.out.println("Error: " + e); } // Get source image dimension int width = simg.getWidth(); int height = simg.getHeight(); // BufferedImage for mirror image BufferedImage mimg = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB); // Create mirror image pixel by pixel for (int y = 0; y < height; y++) { for (int lx = 0, rx = width - 1; lx < width; lx++, rx--) { // lx starts from the left side of the image // rx starts from the right side of the // image lx is used since we are getting // pixel from left side rx is used to set // from right side get source pixel value int p = simg.getRGB(lx, y); // set mirror image pixel value mimg.setRGB(rx, y, p); } } // save mirror image try { f = new File( "C:/Users/hp/Desktop/Image Processing in Java/GFG.png"); ImageIO.write(mimg, "png", f); } catch (IOException e) { System.out.println("Error: " + e); } } } Output: Note: This code will not run on online ide since it requires an image in the drive. Comment K kartik 5 Improve K kartik 5 Improve Article Tags : Java Image-Processing Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like