Adding Watermark to Photos
Contents
[
Hide
]
Add watermark to photos or multi-framed images in Java
GroupDocs.Watermark for Java which is a part of Conholdate.Total for Java, allows you to add watermark to photos or images.
The following steps demonstrates how to add an ImageWatermark to a document from a stream:
- Create a watermarker for the file stream (line 4);
- Create an image watermark from the local image file (line 6);
- Set the watermark horizontal and vertical alignments (lines 7, 8);
- Add the watermark to the document (line 9);
- Save the document to the new file (line 11).
- Close the watermark and free its resources (line 13);
- Close the watermarker and free its resources (line 14).
Code Snippet
// Constants.InDocumentXlsx is an absolute or relative path to your document. Ex: "C:\\Docs\\document.xlsx"
FileInputStream stream = new FileInputStream(Constants.InDocumentXlsx);
Watermarker watermarker = new Watermarker(stream);
ImageWatermark watermark = new ImageWatermark(Constants.LogoPng);
watermark.setHorizontalAlignment(HorizontalAlignment.Center);
watermark.setVerticalAlignment(VerticalAlignment.Center);
watermarker.add(watermark);
watermarker.save(Constants.OutDocumentXlsx);
watermark.close();
watermarker.close();
stream.close();