Support for adding diagonal water mark using Aspose.Imaging for .NET

See topic: Add diagonal watermark to existing .tif
I’m not understand what matrix.Translate() method do.
Suggest I have image, and want add some diagonal string.
At first, how looks result before I try change angle (coordinates: X = 50, Y = 50): original.png (130.2 KB)
I’m try just create Matrix object, and set rotation angle (without Translate method):
Matrix matrix = new Matrix();
// matrix.Translate(0,0);
matrix.Rotate(45);
graphics.Transform = matrix;
We get result: result.png (129.9 KB)
Of course, its wrong result (position of text). Angle is good.
What Translate method do?
If try like that:
Matrix matrix = new Matrix();
matrix.Translate(50,50);
matrix.Rotate(45);
graphics.Transform = matrix;
Then result is next: result.png (129.9 KB)
How must be (approximately): result.png (130.0 KB)
I achieved this experimentally by random changing Translate method arguments:
Matrix matrix = new Matrix();
matrix.Translate(75,-25);
matrix.Rotate(45);
graphics.Transform = matrix;

@tvv91,

I have observed your requirements and like to share that Translate method in Matrix class is actually used to move the position of selected matrix. I have observed the outputs shared by you and request you to please provide the working sample project along with source files and desired generated output. We will investigate that further on our end to help you out.

Code without rotation:

float x = 200;
float y = 50;
float fontSize = 44;
string textAnnotation = “some text”;
Aspose.Imaging.Image image = Image.Load(@“C:\input.png”);
Aspose.Imaging.Font font = new Aspose.Imaging.Font(“Arial”, fontSize);
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
format.Alignment = Aspose.Imaging.StringAlignment.Near;
format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
/*
Matrix matrix = new Matrix();
matrix.Translate(x, y);
matrix.Rotate(90);
graphics.Transform = matrix;
*/
graphics.DrawString(textAnnotation, font, brush, 200, 50, format);
image.Save(@“C:\result.png”);

Result: result.png (130.2 KB)
Then I try rotate 90 degree:

float x = 200;
float y = 50;
float fontSize = 44;
string textAnnotation = “some text”;
Aspose.Imaging.Image image = Image.Load(@“C:\input.png”);
Aspose.Imaging.Font font = new Aspose.Imaging.Font(“Arial”, fontSize);
Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
format.Alignment = Aspose.Imaging.StringAlignment.Near;
format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
> Matrix matrix = new Matrix();
> matrix.Translate(x, y);
> matrix.Rotate(90);
> graphics.Transform = matrix;
graphics.DrawString(textAnnotation, font, brush, 0, 0, format);
image.Save(@“C:\result.png”);

Result: result.png (129.5 KB)
Angle is good, but position is wrong. Position must be approximately like that: 123.png (56.6 KB)

@tvv91,

I have worked with source file and sample code and manipulated different coordinates to help you out. Can you please try to use following sample code on your end and share feedback with us.

string path = “F:\Aspose Work\”;

  	Aspose.Imaging.License license = new Aspose.Imaging.License();
  	license.SetLicense(path+"Aspose.Total.lic");
  	float x = 110;
  	float y = 60;
  	float fontSize = 44;
  	string textAnnotation = "some text";
  	Aspose.Imaging.Image image = Image.Load(path+"input.png");
  	Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", fontSize);
  	Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
  	Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
  	Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
  	format.Alignment = Aspose.Imaging.StringAlignment.Near;
  	format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
        Matrix matrix = new Matrix();
        matrix.Translate(x, y);
        graphics.Transform = matrix;
  	graphics.DrawString(textAnnotation, font, brush, 0, 0, format);
  	image.Save(path+"resultalex.png");

You are not understand problem, or, I’am explain it’s bad. Ok, lets try another way. I’m get coordinates from you code (110, 60), and draw simple vertical and horizontal lines that started from this coordinates.
So, source file now is: input.png (128.7 KB)

Now, lets draw string using you code with coordinates 110, 60. Result: result.png (130.2 KB)
All is good. Now lets try rotate string by 90 degree (coordinates not changed (110, 60):

Matrix matrix = new Matrix();
matrix.Translate(x, y);
matrix.Rotate(90);
graphics.Transform = matrix

Result: result.png (129.8 KB)
Angle is good, but position of “some text” is wrong.result.png (76.2 KB)

@tvv91,

I have worked with the sample files shared by you and have been able to observe the issue specified. An issue with ID IMAGINGNET-3263 has been created in our issue tracking system to investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.