Mirroring an image Vertical in Java

Mirroring an image is very easy and quite interesting effect that rarely can be used. Mirroring an image is similar to placing a image on mirror so that left side of image shows up in mirror. We will apply couple different techniques.

Mirroring image pixels along a vertical Line

First of all find the mirroring point. That can be center of each row. Now, what we are going to do is to copy and replace left half of image to right half side. To achieve this we will obtain the width of an image. Now we are change the color of pixel of right pixel(width-x,0) with pixel(0,0) that is most left side. The value of x will change after each iteration until reach middle of image. This will setup new color half image portion of right side with pixel(0,0), pixel(1,0), pixel(2,0) and son on.
We can mirror pixel from left to right and right to left too. Let’s have a look at method below. Add this method to MyPicture class to use it in your code.

The following code mirror image from right to left.

Original Image

Original Image

Here is the result taken after implementing above method.

right to left mirror image

right to left mirror image

Here is another example to mirror image pixel from left to right.

Left to right mirror

Left to right mirror

No Responses