Draw smooth text on Transparent bitmap
-
How can I draw smooth text on a transparent bitmap using GDI functions? What I do is: 1- Creating myBitmap 2- Creating Graphics object from myBitmap 3- Getting bitmap hDC 4- Setting background mode to TRANSPARENT 5- Drawing text using DrawText function 6- Releasing bitmap HDC 7- Saving Bitmap The result is an ugly text! the text is not smoothed but when I set background mode to OPAQ using SetBkMode the result is smoothed. How can I draw smooth text on a transparent bitmap using GDI functions? any help will be appreciated. My code is like this:
Bitmap myBitmap=new Bitmap(100,100,Format32bppArgb); Graphic g=Graphics.FromImage(myBitmap); IntPtr hDC=g.GetHDC(); SetBkMode(hDC, TRANSPARENT); DrawText(hdc, "Test", -1, myrectangle,myflags); g.ReleaseHdc(hDC); myBitmap.Save("myBitmap.png",ImageFormat.Png);
modified on Thursday, August 20, 2009 6:54 AM
-
How can I draw smooth text on a transparent bitmap using GDI functions? What I do is: 1- Creating myBitmap 2- Creating Graphics object from myBitmap 3- Getting bitmap hDC 4- Setting background mode to TRANSPARENT 5- Drawing text using DrawText function 6- Releasing bitmap HDC 7- Saving Bitmap The result is an ugly text! the text is not smoothed but when I set background mode to OPAQ using SetBkMode the result is smoothed. How can I draw smooth text on a transparent bitmap using GDI functions? any help will be appreciated. My code is like this:
Bitmap myBitmap=new Bitmap(100,100,Format32bppArgb); Graphic g=Graphics.FromImage(myBitmap); IntPtr hDC=g.GetHDC(); SetBkMode(hDC, TRANSPARENT); DrawText(hdc, "Test", -1, myrectangle,myflags); g.ReleaseHdc(hDC); myBitmap.Save("myBitmap.png",ImageFormat.Png);
modified on Thursday, August 20, 2009 6:54 AM
Hi, Not 100% sure but I don't think you can get smooth text on transparent backgrounds. Font smoothing normally happens by blending foregroundColor and backgroundColor at the edges of the glyphs; nothing blends with transparent, whatever you add to it remains transparent. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, Not 100% sure but I don't think you can get smooth text on transparent backgrounds. Font smoothing normally happens by blending foregroundColor and backgroundColor at the edges of the glyphs; nothing blends with transparent, whatever you add to it remains transparent. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Thank you for your comment. But using GDI+, when you draw a text on transparnet background and save the image you will see that the font smoothing is completely good. It seems here font smoothing take place by Mixing Font color with Transparent color, using Alpha value in ARGB. Also Applications like Photoshop do the job well. So there should be a win32(GDI)approach to drawing smooth text on transparent bitmaps. in GDI+ the code is like to this:
Bitmap myBitmap=new Bitmap(100,100,Format32bppArgb); Graphic g=Graphics.FromImage(myBitmap); g.DrawString("Test", Font, Brushes.Black, 0, 0); myBitmap.Save("myBitmap.png",ImageFormat.Png);