Hi
Please refer below code.
HTML
<div>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Chrysanthemum.jpg" />
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string watermarkText = "© aspsnippet.com";
string fileName = Server.MapPath(Image1.ImageUrl);
FileStream fs = new FileStream(fileName, FileMode.Open);
using (Bitmap bmp = new Bitmap(fs, false))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
Brush brush = new SolidBrush(Color.Red);
Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
using (MemoryStream memoryStream = new MemoryStream())
{
bmp.Save(memoryStream, ImageFormat.Png);
string base64String = Convert.ToBase64String(memoryStream.ToArray());
string imageUrl = "data:image/png;base64," + base64String;
Image1.Attributes.Add("src", imageUrl);
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Me.IsPostBack Then
Dim watermarkText As String = "© aspsnippet.com"
Dim fileName As String = Server.MapPath(Image1.ImageUrl)
Dim fs As FileStream = New FileStream(fileName, FileMode.Open)
Using bmp As Bitmap = New Bitmap(fs, False)
Using grp As Graphics = Graphics.FromImage(bmp)
Dim brush As Brush = New SolidBrush(Color.Red)
Dim font As Font = New System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel)
Dim textSize As SizeF = New SizeF()
textSize = grp.MeasureString(watermarkText, font)
Dim position As Point = New Point((bmp.Width - (CInt(textSize.Width) + 10)), (bmp.Height - (CInt(textSize.Height) + 10)))
grp.DrawString(watermarkText, font, brush, position)
Using memoryStream As MemoryStream = New MemoryStream()
bmp.Save(memoryStream, ImageFormat.Png)
Dim base64String As String = Convert.ToBase64String(memoryStream.ToArray())
Dim imageUrl As String = "data:image/png;base64," & base64String
Image1.Attributes.Add("src", imageUrl)
End Using
End Using
End Using
End If
End Sub
Screenshot