this slowpoke moves

Draw Text Typewriter on Image

procedure VerticalTypewriter(text: string; image: timage; delay: integer);
var
 x,y,i: integer;
begin
 Image.Canvas.Refresh;
 Application.ProcessMessages;
 y := 1;

 for i := 1 to length(text) do begin
  Application.ProcessMessages;
  y := y+image.Canvas.TextHeight(text[i]);
  x := Image.width div 2 - (Image.Canvas.TextWidth(text[i]) div 2);
  Image.Canvas.TextOut(x,y,text[i]);
  sleep(delay);
 end;
end;

procedure HorizontalTypewriter(text: string; image: timage; delay, space: integer);
var
 x,y,i: integer;
begin
 Image.Canvas.Refresh;
 Application.ProcessMessages;
 x := 1;

 for i := 1 to length(text) do begin
  Application.ProcessMessages;
  y := Image.Picture.Height div 2 - (Image.Canvas.TextHeight(text[i]) div 2);
  x := x + Image.Canvas.TextWidth(text[i])+space;
  Image.Canvas.TextOut(x,y,text[i]);
  sleep(delay);
 end;

end;
Beispiel Vertikal :
procedure TForm1.Button1Click(Sender: TObject);
begin
  VerticalTypewriter('HELLO WORLD',   Image1, 100);
end;
Beispiel Horizontal :
procedure TForm1.Button1Click(Sender: TObject);
begin
  HorizontalTypewriter('Hello World',  Image1,  100,  3);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate