Solved

Put text in a picture ASP.NET C#

Posted on 2016-10-07
2
47 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 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 41833899
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.
ID: 41835066
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

943 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

10 Experts available now in Live!

Get 1:1 Help Now