निम्न Java उदाहरण दी गई इमेज पर एक वॉटरमार्क (“Hello”) बनाता है और इसे वापस सेव करता है।
उदाहरण
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class WaterMarkExample { public static void main(String[] args) throws IOException { // इमेज की सामग्री पढ़ रहा है File file = new File("D:\\Images\\test1.jpg"); BufferedImage img = ImageIO.read(file); // आउटपुट के लिए एक खाली इमेज बना रहा है int height = img.getHeight(); int width = img.getWidth(); BufferedImage res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ग्राफिक्स ऑब्जेक्ट बना रहा है Graphics graphics = res.getGraphics(); graphics.drawImage(img, 0, 0, null); // वॉटरमार्क के लिए फॉन्ट बना रहा है Font font = new Font("Arial", Font.PLAIN, 45); graphics.setFont(font); graphics.setColor(new Color(255, 150, 200, 30)); // इमेज पर वॉटरमार्क स्ट्रिंग बना रहा है graphics.drawString("Hello", width/7, height/5); // स्ट्रिंग को डिस्पोज कर रहा है graphics.dispose(); // परिणाम इमेज लिख रहा है। file = new File("D:\\Images\\watermark.jpg"); ImageIO.write(res, "jpg", file); } }इनपुट

आउटपुट
