• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 104
  • Last Modified:

Put text in a picture ASP.NET C#

We have a file called BLUE.PNG and is located in c:\pictures
This is that file example:

Now in ASP.NET C# we want to process information and some variables and after that put some text over the picture and save like BLUEMOD.PNG in same c:\pictures directory. For example the next picture is text over the first picture:

That text will be generated via string variables or whatever. How can we do then to put text over a picture in ASP.NET C# and save the results in other file?

Any ideas?
Alex E.
Alex E.
1 Solution
käµfm³d 👽Commented:
You need to bring in the Drawing library for this purpose. You can make use of a Graphics object to draw on the image.


static byte[] DrawOnImage(byte[] imageData, string text)
    using (MemoryStream ms = new MemoryStream(imageData))
        using (Image img = Image.FromStream(ms))
            using (Graphics g = Graphics.FromImage(img))
                g.DrawString(text, new Font("Arial", 12F), Brushes.Black, new PointF(50, 40));

            ms.Position = 0;    // Important!

            img.Save(ms, ImageFormat.Png);

        return ms.ToArray();

Open in new window

byte[] imageBytes = File.ReadAllBytes("blue.png");
byte[] modifiedBytes = DrawOnImage(imageBytes, "Example of text");

File.WriteAllBytes("blue2.png", modifiedBytes);

Open in new window

Alex E.Author Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now