In this section , you will see how to flip image.
To reverse the image, an image is put into the folder where class is specified. The getDefaultToolkit() method of ToolKit class provides the default toolkit. The method getImage() of class ToolKit returns an image.
The MediaTracker class provides a media objects including images. Create an instance of MediaTracker and call addImage() method which adds an image. The method waitForAll() of this class loads the image which is added.
To wrap one or more data arrays to store image data, we have used the class DataBuffer. The method getDataBuffer() retrieves the data buffer. The method getSize() of DataBuffer class returns the size of all data arrays. To return the requested element from the array, the method getElem(i) is used. The method setElem(j, buffer1.getElem(i)) sets the requested element in the array.
We have create two objects of class DataBuffer, i.e., buffer1 which retrieves the the data buffer of bufferedImage1 and buffer2 retrieves the data buffer of bufferedImage2. The two objects bufferedImage1 and bufferedImage2 of class BufferedImage class acts as a source image and the destination image respectively. The destination image is the flipped image.
Here is the code of FlipImageExample.java
Output will be displayed as:
On clicking the button, the image will get reverse.
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial