Solved

Put text in a picture ASP.NET C#

Posted on 2016-10-07
2
72 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.
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

731 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