hi friends,
i’m trying add watermark to a tif image but whatever I’ve done, can not change font size and color. here is my java code and my image file is in attachment.
public static void water2tiff() {
Locale.setDefault(Locale.ENGLISH);
String filePath = “D:/test/asposeTiff/tifFile.tif”;
String theString = “45 Degree Rotated Text”;
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(filePath);
com.aspose.imaging.Graphics graphics = new com.aspose.imaging.Graphics(image);
com.aspose.imaging.Size size = graphics.getImage().getSize();
com.aspose.imaging.Font font = new com.aspose.imaging.Font(“Times New Roman”, 40f);
com.aspose.imaging.brushes.SolidBrush brush = new com.aspose.imaging.brushes.SolidBrush();
brush.setColor(com.aspose.imaging.Color.getRed());
brush.setOpacity(0);
com.aspose.imaging.StringFormat format = new com.aspose.imaging.StringFormat();
format.setAlignment(com.aspose.imaging.StringAlignment.Center);
format.setFormatFlags(com.aspose.imaging.StringFormatFlags.MeasureTrailingSpaces);
com.aspose.imaging.Matrix matrix = new com.aspose.imaging.Matrix();
matrix.translate(size.getWidth() / 2, size.getHeight() / 2);
matrix.rotate(-45.0f);
graphics.setTransform(matrix);
graphics.drawString(theString, font, brush, 0, 0, format);
image.save(“D:/test/asposeTiff/tifFileOut.tif”);
}
thanks for help,
Best regards.
Hi there,
Thank you for using Aspose products.
We are able to replicate the problem of text color not being adjusted while using the latest version of Aspose.Imaging for Java 2.1.0. We have noticed that irrespective of the brush color specified, the rendered text on the image is always black. Although we were able to set different font sizes using your provided code snippet on a sample of our own. Please note, the fonts size has to be set using the Font class.
We have logged a ticket (IMAGING-34122) in our bug tracking system to look further into the matter of setting brush colors. Please spare us little time to properly analyze the problem cause, and to provide a fix at earliest. In the meanwhile, we will keep you posted with updates in this regard.
Regarding your shared Tiff image, please note, we were unable to load the sample into in instance of Image class. We have experienced an exception with message, “Unable to read file. Exception:Unable to read values for Xresolution tag. Message : Cannot read 8 bytes from the stream”. Reason being, the image does not have resolution parameters specified as we have checked it with IrfanView -> Image -> Information. Please check attached snapshot empty-resolution.png. When we manually updated the resolution and saved a copy, the API can read the image just fine. We would like to inquire about the origin of this image to make improvements in Aspose.Imaging APIs.
Hi again,
This is to update you regarding the ticket logged earlier as IMAGING-34122. The said problem is caused due to the reason that the source image is black n white therefore when you draw a string over it and save without additional settings, the color of the brush (text) converts to black. We would suggest you to save the resultant image in RGB format using the following piece of code, whereas the code to draw the text (watermarking) remains the same.
Java
//Save output to disk
TiffOptions tiffOptions = new TiffOptions();
tiffOptions.setBitsPerSample(new int[] { 8, 8, 8 });
tiffOptions.setPhotometric(TiffPhotometrics.Rgb);
image.save(myDir + “output.tif”, tiffOptions);
Please feel free to write back in case you find any ambiguity.
The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.