I want to find a method to add and remove a known watermark from image with Java.
I have an image1.png and a watermark watermark.png
I want to find a method to addWatermark(image1, watermark)
--> image2.png
And then I want to recover the origin image like this removeWatermark(image2, watermark)
--> image1.png
Can anyone give me a suggestion for this problem?
To overlay two images you can just use the following java code:
File path = ... // base path of the images and the result
// load images
BufferedImage image = ImageIO.read(new File(path, "image.png"));
BufferedImage watermark = ImageIO.read(new File(path, "watermark.png"));
// create the new image, size is the max. of both image sizes
int w = Math.max(image.getWidth(), watermark.getWidth());
int h = Math.max(image.getHeight(), watermark.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// now just paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(watermark, 0, 0, null);
g.dispose();
// Save this as a new image
ImageIO.write(combined, "PNG", new File(path, "combined.png"));
The removal of watermarks, as the previous speakers have already mentioned, is not that easy.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.