Re: StretchBlt and text



On Wed, 10 May 2006 17:21:59 +0100, "Mike D Sutton" <EDais@xxxxxxxx>
wrote:

What's the most efficient and easy (assuming both can be done) way of
putting transparent text over a StretchBlted bitmap?

The context is a map display, on which I need to place various labels,
for example the names of towns and cities, which I'm currently doing
with a control array of transparent labels - not a very satisfactory
method for various reasons.

I could imagine having an invisible PictureBox, printing the text
fields into there and blatting each image to the main map, but I'm not
sure if that's the best way, and would like to check before I
investigate how to do that.

It would be nice to have control of the size, font, colour, etc of the
text too, if that's a consideration.

Probably the easiest way would be to use the TextOut() API call, however
this does have to rasterise the text each time its called and if fonts
change between bits of text this can add further overhead. One potential
optimisation is to pre-render the text onto a back-buffer and blit it from
there, however this would not take into account cleartype or anti-aliasing
and would still require a couple of blits to render without a background.
Another option is to make your text back buffer a 32-bit DIB and
AlphaBlend() from it, which would enable to you take advantage of
anti-alising (or even semi-transparent/fading text labels which may be
interesting to you) however on older machines/OS/graphics cards AlphaBlend()
was a little sluggish.
Of course if the text or it's font (i.e. size, colour, face etc.) are
dynamic then this further complicates things, and you need to balance out
the advantages of using a back-buffer against simply rendering the text each
frame. If I were you, I'd start off with rendering the labels using
TextOut() at runtime and see where that gets you, if you're still not
getting the performance you need then investigate the back-buffer route.
Hope this helps,

Thanks again, Mike - I'll do what you suggest, look at TextOut() and
see how goes.

I'm not *too* concerned about performance, since the app will always
be run on pretty high-spec machines, and the text would only change
during a zooming or panning operation, when the whole visible portion
of the map is redisplayed anyway. During drag-panning with the mouse,
it would be acceptable not to display labels on the map until the
button's released.

Font, font size and colour issues and so on I'll look into when I've
got more of a feel for how it appears visually - it might not be an
issue.
--
John Hatpin
.


Loading