Created
January 28, 2021 02:10
-
-
Save aspose-com-gists/013c207eaf0c3750e9c31c38a8d14100 to your computer and use it in GitHub Desktop.
Add Watermark to Images in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load image | |
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.png"); | |
// Create and initialize an instance of Graphics class | |
Graphics graphics= new Graphics(image); | |
// Creates an instance of Font | |
Font font = new Font("Times New Roman", 16, FontStyle.Bold); | |
// Create an instance of SolidBrush and set its properties | |
SolidBrush brush = new SolidBrush(); | |
brush.setColor(Color.getBlack()); | |
brush.setOpacity(100); | |
Size sz = graphics.getImage().getSize(); | |
// Create an object of Matrix class for transformation | |
Matrix matrix = new Matrix(); | |
// First a translation then a rotation | |
matrix.translate(sz.getWidth() / 2, sz.getHeight() / 2); | |
matrix.rotate(-45.0f); | |
// Set the Transformation through Matrix | |
graphics.setTransform(matrix); | |
// Draw a string using the SolidBrush and Font objects at specific point | |
graphics.drawString("Watermark by Aspose.Imaging for Java", font, brush, 0, 0); | |
// Save image | |
image.save("watermarked-image.png"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load image | |
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.png"); | |
// Create and initialize an instance of Graphics class | |
Graphics graphics= new Graphics(image); | |
// Creates an instance of Font | |
Font font = new Font("Times New Roman", 16, FontStyle.Bold); | |
// Create an instance of SolidBrush and set its properties | |
SolidBrush brush = new SolidBrush(); | |
brush.setColor(Color.getBlack()); | |
brush.setOpacity(100); | |
// Draw a string using the SolidBrush and Font objects at specific point | |
graphics.drawString("Watermark by Aspose.Imaging for Java", font, brush, new PointF(image.getWidth()-100, image.getHeight()-100)); | |
// Save image | |
image.save("watermarked-image.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment