"Learning gives Creativity,Creativity leads to Thinking, Thinking provides Knowledge, Knowledge makes you Great"
Showing posts with label BufferedImage. Show all posts
Showing posts with label BufferedImage. Show all posts
Wednesday, 23 July 2014
Thursday, 19 June 2014
Thursday, 22 May 2014
Merging two images
Just create a new BufferedImage with transparency, then paint the other two images (with full or semi-transparency) on it.
This is how it will look like:
Sample code (images are called 'image.png' and 'overlay.png'):
File path = ... // base path of the images
// load source images
BufferedImage image = ImageIO.read(new File(path, "image.png"));
BufferedImage overlay = ImageIO.read(new File(path, "overlay.png"));
// create the new image, canvas size is the max. of both image sizes
int w = Math.max(image.getWidth(), overlay.getWidth());
int h = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 0, 0, null);
// Save as new image
ImageIO.write(combined, "PNG", new File(path, "combined.png"));
Saturday, 10 August 2013
Subscribe to:
Posts (Atom)