WaterMark on Image

Hi Team.

Im try add watermark to img from data base for display image Component on templateform.

templatefrom component Image ${employee.Photo}' from data base.ok
load string '${Security.User.Name}'. ok

add string '${Security.User.Name}' + '${employee.Photo}' = new '${employee.PhotoWatermark}'

I am doing a small watermark solution.

Search the database for an image.
Perform a process to take that image + the current user "in my case, User name String".
Create a new temporary image with the watermark.
That will be displayed in a templatefrom in the Image component.

But don't work properly in mi case. im using a nugget called Drawing.
if u have a better solutions i would be very grateful.


like this one. need to change

Drawing


Try in C#

{
string watermarkText = '(Security.User.Name)';
   
//Get the file name.
string fileName = '(employee.Photo)';

//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(FileLoad.PostedFile.InputStream, false))
{
    using (Graphics grp = Graphics.FromImage(bmp))
    {
        //Set the Color of the Watermark text.
        Brush brush = new SolidBrush(Color.Red);

        //Set the Font and its size.
        Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);

        //Determine the size of the Watermark text.
        SizeF textSize = new SizeF();
        textSize = grp.MeasureString(watermarkText, font);

        //Position the text and draw it on the image.
        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())
}

This code is valid for ASP.NET only, not for .NET 5/6 (Core). You can search StackOverflow for more modern solution.