We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose Imaging the speed problem of adding watermark

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);

    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);

            // Set the Transformation through Matrix
            // Draw a string using the SolidBrush and Font objects at specific point
            graphics.drawString(watermarkText, font, brush, 0, 0);


    // Save image


Actually, this is the option that you can use to add watermark to your image. I have already shared a similar example in another thread as well.

Thank you for your reply,but what I mean is to spread the watermark over the whole picture, not adding watermark to every page of TIF. I can’t uploading pictures,just use words to show like this:

| watermark watermark watermark |
| watermark watermark watermark |
| watermark watermark watermark |


Can you please provide the desired output. Also, you can use Graphics object to place the text any where on image and can have multiple instances for multiple places. There is no other option available.

Isn’t there a way to cover an entire image without using a loop, and just call graphics.drawstring over and over again to add a watermark? That’s a little inefficient, um


Well there is no other way then to add watermark on different places by repetition.