代码大致意思是根据时间算出一个字母走过的百分比,然后再根据百分比让字幕变色,实际就是在画一边,这是一个一次画两行的函数,我想变成多行的,也就是说我想变成可以显示N行大家帮我优化一下,up有分!级别不够,如果有好意见另开贴给分,一定!
procedure TLyric_form.DrawLyricLine(ALine,next_aline: string; Percent: Real);
var
ABmp, bBmp, cBmp, dBmp: TBitmap;
h,hl,w,wl,h2,hl2,w2,wl2: Integer;
ARect, bRect: TRect;
begin
if Percent < 0 then Exit;
ABmp := TBitmap.Create;
BBmp := TBitmap.Create;
cBmp := TBitmap.Create;
dBmp := TBitmap.Create;
try
ABmp.Width := Lyric_form.Width ;
ABmp.Height :=Lyric_form .Height div 2;
ABmp.Canvas.Brush.Color := clBlack;
ABmp.Canvas.FillRect(Rect(0,0,ABmp.width, ABmp.Height));
bBmp.Assign(abmp);
bbmp.Canvas.Brush := ABmp.Canvas.Brush;
ABmp.Canvas.Font :=Lyric_form.Canvas.Font;
Bbmp.Canvas.Font := Lyric_form.Canvas.Font;
// ABmp.Canvas.Font := pb.Font;
// bbmp.Canvas.Font := pb.Font;
h := ABmp.Canvas.TextHeight(Aline);
w := ABmp.Canvas.TextWidth(Aline);
wl := (aBmp.Width-w) div 2;
hl := (aBmp.Height-h) div 2;
aBmp.Canvas.Font.Color := clWhite;
ABmp.Canvas.TextOut(wl, hl, ALine);
bBmp.Canvas.Font.Color := clLime;
bBmp.Canvas.TextOut(wl, hl, ALine);
aRect := Rect(wl, hl, wl+ trunc(w*Percent/100), hl+h);
abmp.Canvas.CopyRect(aRect, bbmp.Canvas, arect); if (CurrentLine mod 2) = 0 then
Lyric_form.Canvas.Draw(0,0,abmp)
else
Lyric_form.Canvas.Draw(0,Height div 2,abmp); //pb.Canvas.Draw(0,0, aBmp); //画第二行
//pb变黑
cBmp.Width := Lyric_form.Width;
cBmp.Height := Lyric_form.Height div 2;
cBmp.Canvas.Brush.Color := clBlack;
cBmp.Canvas.FillRect(Rect(0,0,cBmp.width, cBmp.Height));
//准备在黑色地板上画白字
dBmp.Assign(cbmp);
dbmp.Canvas.Brush := cBmp.Canvas.Brush;
cBmp.Canvas.Font := Lyric_form.Canvas.Font;
dbmp.Canvas.Font := Lyric_form.Canvas.Font;
//cBmp.Canvas.Font := pb1.Font;
//dbmp.Canvas.Font := pb1.Font;
//字的大小 位置
h2 := cBmp.Canvas.TextHeight(next_aline);
w2 := cBmp.Canvas.TextWidth(next_aline);
wl2 := (cBmp.Width -w2) div 2;
hl2 := (cBmp.Height -h2) div 1;
//画出白字
cBmp.Canvas.Font.Color := clWhite;
cBmp.Canvas.TextOut(wl2, hl2,next_aline);
//准备给白子上色变成绿的
dBmp.Canvas.Font.Color := clLime;
dBmp.Canvas.TextOut(wl2, hl2, next_aline);
bRect := Rect(wl2, hl2, wl2+ trunc(w2*0), hl2+h2);
cbmp.Canvas.CopyRect(bRect, dbmp.Canvas, brect); if (CurrentLine mod 2)=0 then
Lyric_form.Canvas.Draw(0,Height div 2 ,cbmp)
else
Lyric_form.Canvas.Draw(0,0 ,cbmp)
//pb1.Canvas.Draw(0,0, cBmp);
finally
ABmp.Free;
bBmp.Free;
cBmp.Free;
dBmp.Free;
end;
end;
procedure TLyric_form.DrawLyricLine(ALine,next_aline: string; Percent: Real);
var
ABmp, bBmp, cBmp, dBmp: TBitmap;
h,hl,w,wl,h2,hl2,w2,wl2: Integer;
ARect, bRect: TRect;
begin
if Percent < 0 then Exit;
ABmp := TBitmap.Create;
BBmp := TBitmap.Create;
cBmp := TBitmap.Create;
dBmp := TBitmap.Create;
try
ABmp.Width := Lyric_form.Width ;
ABmp.Height :=Lyric_form .Height div 2;
ABmp.Canvas.Brush.Color := clBlack;
ABmp.Canvas.FillRect(Rect(0,0,ABmp.width, ABmp.Height));
bBmp.Assign(abmp);
bbmp.Canvas.Brush := ABmp.Canvas.Brush;
ABmp.Canvas.Font :=Lyric_form.Canvas.Font;
Bbmp.Canvas.Font := Lyric_form.Canvas.Font;
// ABmp.Canvas.Font := pb.Font;
// bbmp.Canvas.Font := pb.Font;
h := ABmp.Canvas.TextHeight(Aline);
w := ABmp.Canvas.TextWidth(Aline);
wl := (aBmp.Width-w) div 2;
hl := (aBmp.Height-h) div 2;
aBmp.Canvas.Font.Color := clWhite;
ABmp.Canvas.TextOut(wl, hl, ALine);
bBmp.Canvas.Font.Color := clLime;
bBmp.Canvas.TextOut(wl, hl, ALine);
aRect := Rect(wl, hl, wl+ trunc(w*Percent/100), hl+h);
abmp.Canvas.CopyRect(aRect, bbmp.Canvas, arect); if (CurrentLine mod 2) = 0 then
Lyric_form.Canvas.Draw(0,0,abmp)
else
Lyric_form.Canvas.Draw(0,Height div 2,abmp); //pb.Canvas.Draw(0,0, aBmp); //画第二行
//pb变黑
cBmp.Width := Lyric_form.Width;
cBmp.Height := Lyric_form.Height div 2;
cBmp.Canvas.Brush.Color := clBlack;
cBmp.Canvas.FillRect(Rect(0,0,cBmp.width, cBmp.Height));
//准备在黑色地板上画白字
dBmp.Assign(cbmp);
dbmp.Canvas.Brush := cBmp.Canvas.Brush;
cBmp.Canvas.Font := Lyric_form.Canvas.Font;
dbmp.Canvas.Font := Lyric_form.Canvas.Font;
//cBmp.Canvas.Font := pb1.Font;
//dbmp.Canvas.Font := pb1.Font;
//字的大小 位置
h2 := cBmp.Canvas.TextHeight(next_aline);
w2 := cBmp.Canvas.TextWidth(next_aline);
wl2 := (cBmp.Width -w2) div 2;
hl2 := (cBmp.Height -h2) div 1;
//画出白字
cBmp.Canvas.Font.Color := clWhite;
cBmp.Canvas.TextOut(wl2, hl2,next_aline);
//准备给白子上色变成绿的
dBmp.Canvas.Font.Color := clLime;
dBmp.Canvas.TextOut(wl2, hl2, next_aline);
bRect := Rect(wl2, hl2, wl2+ trunc(w2*0), hl2+h2);
cbmp.Canvas.CopyRect(bRect, dbmp.Canvas, brect); if (CurrentLine mod 2)=0 then
Lyric_form.Canvas.Draw(0,Height div 2 ,cbmp)
else
Lyric_form.Canvas.Draw(0,0 ,cbmp)
//pb1.Canvas.Draw(0,0, cBmp);
finally
ABmp.Free;
bBmp.Free;
cBmp.Free;
dBmp.Free;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货