开发者

wx Text with outline

I have a video player written in wxpython and am overlaying the current FPS onto the video.

My text is black, so if the video is sufficiently dark the FPS counter is not visible.

I am looking for a way to draw text with an outline so it will stan开发者_如何学Cd out no matter what the video is displaying. E.g. I want black text with a white outline.

I am currently drawing text directly onto the DC, as so:

dc.DrawBitmap(self.img, 0, 0)

dc.DrawText(str(self.frames), 0, 0)

Thanks for any help!


You are out of luck for any nice built in solution along the lines of options in font selection or pairs of fonts, one to draw the outline, one to draw the interior.

If you are only showing frame per second values and only using digits 0..9 and '.' then use small bitmaps for the numbers created yourself in an image editor, with alpha so that only the central region and outline show.

If you want arbitrary text it's rather more work. Generate the characters with an outline programmatically. Draw the unoutlined font to a bitmap using a wxMemoryDC, convert to a wxImage, GetData() to get the raw data, use a http://en.wikipedia.org/wiki/Sobel_filter to add an outline - and from this you can create the partially transparent bitmap to overlay onto your DC. If you want nice anti-aliasing of the numbers draw them at twice the size you'll use and use a 5x5 kernel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜