Reputation: 1046
I have an image with a plain background. Now I need to place another image onto it at (x, y) location. How is it possible?
Upvotes: 4
Views: 10188
Reputation: 52205
You could use the drawImage method. Maybe something like so:
try
{
BufferedImage source = ImageIO.read(new File("..."));
BufferedImage logo = ImageIO.read(new File("..."));
Graphics g = source.getGraphics();
g.drawImage(logo, 0, 0, null);
}
catch (Exception e)
{
e.printStackTrace();
}
Upvotes: 10
Reputation: 57421
Create a BufferedImage
with desired size. Use getGraphics()
of the image and paint the first image and then the second one. Graphics
has the method
public abstract boolean drawImage(Image img, int x, int y,
Color bgcolor,
ImageObserver observer)
Upvotes: 12