by
8,582 17

How to Add Watermark to an Image inside .NET Applications

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/941827/How-to-Add-Watermark-to-an-Image-inside-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. // Adding a Watermark //[C# Code Sample] //Load an existing JPG image using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(myDir + "sample.jpg")) { //Declare a String object with Watermark Text String theString = "45 Degree Rotated Text"; //Create and initialize an instance of Graphics class Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image); //Initialize an object of SizeF to store image Size Aspose.Imaging.SizeF sz = graphics.Image.Size; //Creates an instance of Font, initialize it with Font Face, Size and Style Aspose.Imaging.Font font = new Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold); //Create an instance of SolidBrush and set its various properties Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(); brush.Color = Aspose.Imaging.Color.Red; brush.Opacity = 0; //Initialize an object of StringFormat class and set its various properties Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat(); format.Alignment = Aspose.Imaging.StringAlignment.Center; format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces; //Create an object of Matrix class for transformation Aspose.Imaging.Matrix matrix = new Aspose.Imaging.Matrix(); //First a translation matrix.Translate(sz.Width / 2, sz.Height / 2); //Then a rotation matrix.Rotate(-45.0f); //Set the Transformation through Matrix graphics.Transform = matrix; //Draw the string on Image graphics.DrawString(theString, font, brush, 0, 0, format); //Save output to disk image.Save(myDir + "output.jpg"); } //[VB.NET Code Sample] 'Load an existing JPG image Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(myDir & "sample.jpg") 'Declare a String object with Watermark Text Dim theString As String = "45 Degree Rotated Text" 'Create and initialize an instance of Graphics class Dim graphics As New Aspose.Imaging.Graphics(image) 'Initialize an object of SizeF to store image Size Dim sz As Aspose.Imaging.SizeF = graphics.Image.Size 'Creates an instance of Font, initialize it with Font Face, Size and Style Dim font As New Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold) 'Create an instance of SolidBrush and set its various properties Dim brush As New Aspose.Imaging.Brushes.SolidBrush() brush.Color = Aspose.Imaging.Color.Red brush.Opacity = 0 'Initialize an object of StringFormat class and set its various properties Dim format As New Aspose.Imaging.StringFormat() format.Alignment = Aspose.Imaging.StringAlignment.Center format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces 'Create an object of Matrix class for transformation Dim matrix As New Aspose.Imaging.Matrix() 'First a translation matrix.Translate(sz.Width / 2, sz.Height / 2) 'Then a rotation matrix.Rotate(-45.0f) 'Set the Transformation through Matrix graphics.Transform = matrix 'Draw the string on Image graphics.DrawString(theString, font, brush, 0, 0, format) 'Save output to disk image.Save(myDir & "output.jpg") End Using
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus