Chức năng này được dựa trên ý tưởng Dave elsberry của.
Có gì khác nhau:
- trận hoà chỉ có bóng một cách minh bạch
- Nó sử dụng ít gần 2 lần RAM
- thông số
procedure DrawShadowText(aCanvas: TCanvas; CONST Text: string; CONST X, Y, Opacity: Integer; TextColor, ShadowColor: TColor);
{ Opacity a value from 0-255:
$00 is completely transparent,
$FF is completely opaque.
$C0 is 75% opaque }
CONST ShadowSize= 1;
VAR
TempBMP: TBitmap;
BlendFunc: BLENDFUNCTION;
H, W: Integer;
begin
BlendFunc.BlendOp := AC_SRC_OVER;
BlendFunc.BlendFlags := 0;
BlendFunc.SourceConstantAlpha := Opacity;
BlendFunc.AlphaFormat := AC_SRC_ALPHA;
{ Create another TBitmap to hold the text you want to overlay }
TempBMP := Graphics.TBitmap.Create;
TRY
TempBMP.Canvas.Font.Style := [fsBold];
TempBMP.Canvas.Brush.Style := bsClear;
W:= TempBMP.Canvas.TextWidth(Text);
H:= TempBMP.Canvas.TextHeight(Text);
TempBMP.SetSize(W+ShadowSize, H+ShadowSize);
{ In AlphaBlend, Black is always 100% transparent. So, paint TempBMP completely Black. }
TempBMP.Canvas.Brush.Color := clBlack;
TempBMP.Canvas.FloodFill(0, 0, clNone, fsBorder);
{ Write the shadow first }
TempBMP.Canvas.Font.Color := ShadowColor;
TempBMP.Canvas.TextOut(ShadowSize, ShadowSize, Text); { Diagonal left shadow }
TempBMP.Canvas.TextOut(ShadowSize, 0, Text); { Left shadow }
{ Draw the text with transparency:
TempBMP.Canvas.Brush.Style := bsClear;
TempBMP.Canvas.Font.Color := TextColor;
TempBMP.Canvas.TextOut(0, 0, Text); }
{ Use the AlphaBlend function to overlay the bitmap holding the text on top of the bitmap holding the original image. }
Windows.AlphaBlend(aCanvas.Handle,
x, y, TempBMP.Width, TempBMP.Height,
TempBMP.Canvas.Handle, 0, 0, TempBMP.Width, TempBMP.Height,
BlendFunc);
{ Draw the text at 100% opacity }
aCanvas.Font.Style := [fsBold];
aCanvas.Brush.Style := bsClear;
aCanvas.Font.Color := TextColor;
aCanvas.TextOut(x, y-1, Text);
FINALLY
FreeAndNil(TempBMP);
END;
end;
procedure TfrmTest.UseIt;
VAR BackgroundImage: tbitmap;
begin
BackgroundImage := Graphics.TBitmap.Create;
try
BackgroundImage.LoadFromFile('c:\test.bmp');
DrawShadowText (BackgroundImage.Canvas, 'This is some demo text', 20, 40, 140, clRed, clSilver);
Image1.Picture.Bitmap.Assign(BackgroundImage);
FINALLY
BackgroundImage.Free;
end;
end;
Progdigy.com đã ngừng hoạt động? Tôi không thể truy cập nó. – Ampere
Dường như có một số bất đồng giữa nhà phát triển 'GDI plus' cho Delphi và Embarcadero, tôi không biết liệu nó có bị kéo theo phản ứng này hay không. Bạn có thể thử tìm kiếm một số lựa chọn thay thế như [GDI plus] của Erik Van Bilsen (http://www.bilsen.com/gdiplus/index.shtml). – Petesh