How to convert text string to image in asp.net MVC c#?

How to convert text string to image in asp.net MVC c#?

 

public FileResult GenerateImage()
        {

            MemoryStream ms = new MemoryStream();
           string text ="usingcsharp.com";
            Image img = new Bitmap(200, 30, System.Drawing.Imaging.PixelFormat.Format64bppArgb);
            Graphics drawing = Graphics.FromImage(img);
            Font font = new Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);
            
            SizeF textSize = drawing.MeasureString(text, font);
            img.Dispose();
            drawing.Dispose();
            //create a new image of the right size
            img = new Bitmap((int)textSize.Width + 30, (int)textSize.Height + 40);
            drawing = Graphics.FromImage(img);
            Color backColor = Color.White;
            Color textColor = Color.FromArgb(1, 119, 245);

            //textColor. = "#0177F5";
            //paint the background
            drawing.Clear(backColor);
            //create a brush for the text
            Brush textBrush = new SolidBrush(textColor);
            drawing.DrawString(text, font, textBrush, 40, 20);
            drawing.Save();
            font.Dispose();
            textBrush.Dispose();
            drawing.Dispose();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            img.Dispose();
            return File(ms.ToArray(), "image/png");

        }

 

<img class="img-fluid img-thumbnail" src="/Home/GenerateImage" alt="@ViewBag.OriginalTitle" id="imgsource1" />

2021-10-03