0

I want to draw a text on top of an image and outside the image area. By this, I mean to produce a new image with the new dimensions. To illustrate, I want to convert a picture like this:

before adding text

to something like this:

after adding text

Also, I want it to be transparent. i.e. the space between the image and text should be transparent. Any idea how I could do this in C# console app?

Moji
  • 251
  • 5
  • 18
  • There are many ways of doing this depending on what you have (JPEG, PDF, BitMap, XAML) and what you want to output. None of which you have told us. – Dour High Arch Mar 13 '20 at 19:27
  • @DourHighArch I actually have both PNG and JPEG formats. It is mostly PNG images though. The output should also be in PNG and transparent. – Moji Mar 13 '20 at 19:32
  • What are you targetting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! – TaW Mar 13 '20 at 20:25
  • Sorry, I should have been more clear. It is for a C# console app. – Moji Mar 14 '20 at 14:36

1 Answers1

1

Easy to do with the System.Drawing library from .net framework. You can do a lot with it. Here's a reference posting from stack overflow, Adding text to image and save

But the long and short of it is:

  1. Create a new blank image in system.drawing to lay your image into.
  2. Lay your image into the blank image. (How do I overlay an image in .NET)
  3. Lay text in that same blank image, outside of your image overlay.

You are done!

Frank Thomas
  • 169
  • 11
  • So basically that means copying the image into a new image with the higher dimensions and adding the text afterward, right? – Moji Mar 13 '20 at 19:34
  • 1
    You got it! That's the way to do it. You have to create a bigger canvas to put the text into. – Frank Thomas Mar 13 '20 at 20:10