Overlapping The Images
This example will help you to understand the concept of Graphics2D better. Just go through the example provided next and see the result. I believe example itself is self-explanatory.
As usual if you have any doubts,clarifications etc you can ask me.
Program :-
package client;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class OverlappingImage {
public static void main(String args[]) {
BufferedImage image1 = null;
BufferedImage image2 = null;
try {
image1 = ImageIO.read(new File("C:/temp/Winter.jpg"));
image2 = ImageIO.read(new File("C:/temp/Sunset.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
Graphics2D g = image1.createGraphics();
g.drawImage(image1, 0, 0, null);
g.drawImage(image2, 100, 10, null);
File file = new File("C:/temp/overLayedImage.jpg");
try {
ImageIO.write(image1, "JPG", file);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Check the new overlapped image");
}
}
Screenshot of output is given below.
Comments
Post a Comment