Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how do i add text to image in c# or vb.net

HELLO,

am an average visual studio programmer, i need a function or routine to add text to the button of an image not on it like i showed in the image alt text

please ideas

[Edit]

  • Am programming with visual studio 2008, on winxp.
  • The application is a console app.
  • it will run on win2000 upwards
  • i will save the result image after adding text to file
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • Create a bitmap with the new size you want

  • Copy the original image at the top of the new bitmap

  • Write the text you want onto the new bitmap

Something like this: (untested)

    var bmp = Bitmap.FromFile("orig.jpg");
    var newImage = new Bitmap(bmp.Width, bmp.Height + 50);

    var gr = Graphics.FromImage(newImage);
    gr.DrawImageUnscaled(bmp, 0, 0);
    gr.DrawString("this is the added text", SystemFonts.DefaultFont, Brushes.Black ,
        new RectangleF(0, bmp.Height, bmp.Width, 50));

    newImage.Save("newImg.jpg");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...