Add Text On Image Using C# Code

In this article, I will explain how can we add text to an Image file using C# code. So let’s start it.

Here, I have created a console application for a small demo. You can use the above code as per your requirement and also update the code as per your requirement. Add the below code to your project.

C# Code:

using System.Drawing;

namespace TextOnImage
{
    class Program
    {
        static void Main(string[] args)
        {
            string TextToWrite = "Originol Product";

            PointF firstLocation = new PointF(10f, 0f);

            string imagePath = @"D:\flower3.png";
            Bitmap img = (Bitmap)Image.FromFile(imagePath);


            using (Graphics graphics = Graphics.FromImage(img))
            {
                using (Font arialFont = new Font("Arial", 35, FontStyle.Bold))
                {
                    graphics.DrawString(TextToWrite, arialFont, Brushes.DarkRed, firstLocation);
                }
            }

            string imageSavingPath = @"D:\flower_Edited.png";
            img.Save(imageSavingPath);
        }
    }
}

Output:

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories