unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs;
type
TForm1 = class(TForm)
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Timer1: TTimer;
Button1: TButton;
Label1: TLabel;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
nowStep: Integer;
const
MaxStep = 40;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
Image1.Canvas.Font.Name := '楷体_GB2312';
Image1.Canvas.Font.Size := 20;
Image1.Canvas.Font.Style := [fsBold]; //加粗
nowStep := 0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.ItemIndex := 0;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
outputstring: string;
x0,y0:Integer;
width:Integer;
begin
x0:=10;
y0:=10;
outputstring := '卡拉OK字幕效果示例';
if nowStep >= MaxStep then
nowStep := 0;
if nowStep=0 then //不变
begin
Image1.Canvas.Brush.Style:= bsClear;
Image1.Canvas.Font.Color:=clBlack;
Image1.Canvas.TextOut(x0,y0,outputstring );
end
else //变化
begin
Image1.Canvas.Brush.Style:=bsClear;
Image1.Canvas.Font.Color:=clRed;
width:=Image1.Canvas.TextWidth(outputstring);
Image1.Canvas.TextRect(Rect(x0,y0,x0+width*nowstep div MaxStep ,y0+image1.Canvas.TextHeight(outputstring))
,x0,y0,outputstring);
end;
nowStep:=nowStep+strtoint(ComboBox1.Items[ComboBox1.itemindex]);
end;
end.