Solved

Put text in a picture ASP.NET C#

Posted on 2016-10-07
2
35 Views
Last Modified: 2016-10-08
We have a file called BLUE.PNG and is located in c:\pictures
This is that file example:

BLUE.PNG
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:

BLUETEXT
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?
0
Comment
Question by:Alex E.
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
You need to bring in the Drawing library for this purpose. You can make use of a Graphics object to draw on the image.

e.g.

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


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

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

Open in new window

0
 

Author Closing Comment

by:Alex E.
Comment Utility
Thank you
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now