GR32 (TBitmap32) 에서 Blurred Text 그리기

Posted by NUL PROG. : 2010. 11. 23. 18:45
늘 그렇듯 간단 팁입니다.


Blurred Text 란건 아래와 같은 걸 의미합니다. (영어가 맞는지는 모르겠지만 제가 쓰는 함수 이름임...;)



흰색 글자지만 배경에 흐릿하게 붉은빛이 돕니다.



이런 텍스트는 아래의 순서대로 출력합니다.

1. 붉은색 텍스트를 출력
2. Blur 처리
3. 흰색으로 다시 덮어 씀.

간단하죠


Blur 효과를 주기 위해 GR32_Lines 에 포함된 TStackBlur를 사용했습니다.
procedure JnDrawBlurredText( BMP: TBitmap32;
                        const Str: String;
                        const X, Y: Integer;
                        const ABlurrColor, ATextColor: TColor32;
                        const ARadius: Integer = 1;
                        const ARepeat: Integer = 3);
var
  i: Integer;
  BmpTxt: TBitmap32;
  szTxt: TSize;
begin
  BmpTxt := TBitmap32.Create;
  try
    BmpTxt.Font.Assign(BMP.Font);

    szTxt := BmpTxt.TextExtent(Str);
    BmpTxt.SetSize(szTxt.cx + ARadius * 2, szTxt.cy + ARadius * 2);

    BmpTxt.Clear(ABlurrColor and $00FFFFFF);
    BmpTxt.RenderText(ARadius, ARadius, Str, 0, ABlurrColor);

    with TStackBlur.Create(ARadius) do
    try
      for i := 1 to ARepeat do
        Execute(BmpTxt);
    finally
      Free;
    end;

    BmpTxt.RenderText(X, Y, Str, 0, ATextColor);
    BmpTxt.DrawMode := dmBlend;

    BmpTxt.DrawTo(BMP, X - ARadius, Y - ARadius);
  finally
    BmpTxt.Free;
  end;
end;