I have a TImage component that I print a Text string to using TCanvas.TextOut(). I set the height and width of the TImage to a large size like 50 pixels X (TextWidth) pixels, and set the Canvas font Height to something a little smaller like 48 pixels. I then BitBlt() the TImage's bitmap on to the main Canvas. What I see on the screen is big skinny letters that are terribly jagged. What I want instead are thick jumbo letters that appear smooth. The reason for using the TImage/BitBlt combo is because I need to do resizing and alpha blending of the text on the fly.
What is the easiest way for me to get big smooth letters to be printed to my TImage bitmap?
Are you never displaying the TImage
? Then you should really use an off-screen bitmap instead. This is a very common technique to achieve double buffering (flicker-free rendering).
For example,
var
bm: TBitmap;
procedure InitOffscreenBitmap;
begin
bm := TBitmap.Create;
bm.SetSize(bmWidth, bmHeight);
end;
procedure DrawBitmap;
begin
// Draw on bm
end;
procedure Swap;
begin
BitBlt(Canvas.Handle, X, Y, bmWidth, bmHeight, bm.Canvas.Handle, 0, 0, SRCCOPY)
end;
If you are using a modern version of Windows (e.g. Vista+), or Windows XP with ClearType enabled (for some very odd reason, it is disabled by default), text should be smooth. Just make sure that you use a modern font. Most of them will do, but very old fonts such as MS Sans Serif cannot be smoothed using ClearType.
Also, naturally, it is imperative that bm
has the same background colour as the form, because alpha-blending will occur when the text is drawn on bm
. So if the form is clRed
(for some perverse reason), you need to do
bm.Canvas.Brush.Color := clRed;
bm.Canvas.Brush.Style := bsSolid;
bm.FillRect(Rect(0, 0, bmWidth, bmHeight));
prior to
bm.TextOut(...)
Just so we are talking about the same thing: Isn't this smooth enough?
procedure TForm3.FormPaint(Sender: TObject);
begin
Canvas.Font.Name := 'Segoe UI';
Canvas.Font.Height := 64;
Canvas.TextOut(10, 10, 'This is an example.');
end;
(High-Res)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With