Is there any way to tile the watermark on the image in a certain format? I use the graphics.Drawstring method to traverse to add watermarks. We find that the performance test is particularly slow. Is there any better way to deal with this situation. Here is my code:
public static void asposeAddTiffWatermark(String sourcePath, String targetPath, String watermarkText) throws IOException {
// Load image
Image image = Image.load(sourcePath);
if (image instanceof TiffImage) {
image = TiffImage.load(sourcePath);
}
// 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.Regular);
// Create an instance of SolidBrush and set itxs properties
SolidBrush brush = new SolidBrush();
Color color = Color.getGray();
float opacity = 0.5f;
int opacityAlpha = (int)(opacity * 255 + 0.5);
color = Color.fromArgb(opacityAlpha, color);
brush.setColor(color);
brush.setOpacity(0.5f);
int height = image.getHeight();
int width = image.getWidth();
for (int x = 10; x < width; x= x+200) {
for (int y = 50; y < height; y = y+100) {
// Create an object of Matrix class for transformation
Matrix matrix = new Matrix();
// First a translation then a rotation
matrix.translate(x, y);
matrix.rotate(350);
// Set the Transformation through Matrix
graphics.setTransform(matrix);
// Draw a string using the SolidBrush and Font objects at specific point
graphics.drawString(watermarkText, font, brush, 0, 0);
}
}
// Save image
image.save(targetPath);
}