Rendering text question (context is MSWin UI Automation)
Boris Borcic
bborcic at gmail.com
Wed Jan 24 09:32:56 EST 2007
Chris Mellon wrote:
>
> Using either win32 or wxPython you will be able to produce bitmaps
> directly, without needing to create a visible window.
>
>
> Some quick & dirty wxPython code
>
> def getTextBitmap(text, font, fgcolor, bgcolor):
> dc = wx.MemoryDC()
> dc.SetFont(font)
> width, height= dc.GetTextExtent(text)
> bmp = wx.EmptyBitmap(width, height)
> dc.SelectObject(bmp)
> dc.SetBackground(wx.Brush(bgcolor))
> dc.Clear()
> dc.SetTextBackground(bgcolor)
> dc.SetTextForeground(fgcolor)
> dc.DrawText(text, 0, 0)
> dc.SelectObject(wx.NullBitmap)
> return bmp
>
>
> Raw win32 code will look similar but will be much more verbose.
Thx again for this base.
Quickly testing this, it appears that the result is rendered half a pixel off in
the x-direction. Does this make sense ? Is it possible to position text with
subpixel accuracy ?
Regards, Boris Borcic
More information about the Python-list
mailing list