1. 程式人生 > >一個很笨的字型勾邊的方法

一個很笨的字型勾邊的方法

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    img_1: TImage;
    Btn_1: TButton;
    Btn_2: TButton;
    procedure Btn_1Click(Sender: TObject);
    procedure Btn_2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Btn_1Click(Sender: TObject);
begin
  img_1.Canvas.Font.Size :=140;
  img_1.Canvas.Font.Name := '華文行楷';
  img_1.Canvas.TextOut( 5,5,'羅韻睿');
end;

procedure TForm1.Btn_2Click(Sender: TObject);
  procedure SetPointerColor(x,y:Integer);
  begin
    if img_1.Canvas.Pixels[x,y] <>clBlack then
      img_1.Canvas.Pixels[x,y] := clRed;
  end;
var
  i,j :Integer;
  p:Pointer;
begin
  for I := 0 to img_1.Width -1 do
  for j := 0 to img_1.Height - 1 do begin
    if img_1.Canvas.Pixels[i,j] =clBlack then begin
      SetPointerColor(i-1,j);
      SetPointerColor(i+1,j);
      SetPointerColor(i,j-1);
      SetPointerColor(i,j+1);
      SetPointerColor(i+1,j+1);
      SetPointerColor(i-1,j-1);
      SetPointerColor(i-1,j+1);
      SetPointerColor(i+1,j-1);
    end;
  end;
end;

end.