2

I'm actually trying to add some text to an image in C# with

System.Windows.Forms.TextRenderer.DrawText(Graphics, string, Rectangle, Color, TextFormaFlags) 

I prepare my image (which is a png) by loading it in memory, with something similar to

Image image = ImageCache.Get(...); bitmap = new Bitmap(image); graphic = Graphics.FromImage(bitmap); 

I then draw my text with the above command. The problem is that whatever I use for the color, even something like

System.Drawing.Color.FromArgb(0,255,255,255) 

the transparency is not drawn. I tried many settings for

graphics.TextRenderingHint 

and different combinations of fonts, transparency level, etc. Is there something I don't understand here? Any hint is appreciated.

Thank you.

4
  • Use Color.Transparent as BackColor or use Graphics.DrawString. See: TextRenderer.DrawText in Bitmap vs OnPaintBackground Commented Feb 9, 2016 at 20:57
  • 1
    If you want alpha blending effects then you must use Graphics.DrawString(), TextRenderer uses GDI which is limited to RGB. Commented Feb 9, 2016 at 21:11
  • @Hans Passant Well, not the answer I wanted to hear, but good to know. If you put it as a formal answer, I'll accept it. Commented Feb 9, 2016 at 21:18
  • 2
    I avoid posting answers that nobody wants to hear. You can post it yourself and accept it. Commented Feb 9, 2016 at 21:20

1 Answer 1

2

As mentionned in the comments : if you try to draw transparent text with

System.Windows.Forms.TextRenderer.DrawText 

because you look for the advantages brought by GDI in C#, you just can't. Use

System.Drawing.Graphics.DrawString 

instead, even if the result for the word-wrapping is slightly inferior with GDI+.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.