procedure TFrmMain.Create_TextBmp(pParent : TPanel; strFile : String); var bmpShowText : TBitMap; //Bmp To Show strTemp : String; //temp string for reading every line ReadFile : TextFile; //Point to open the source text file strItems : TStringList; //itemps of string list to save texts rectDraw, rectTemp : TRect; //total rect for bmp & temp rect for every line iyPos, iLineHet : Integer; //current y Pos to draw one line & line height pDC : HDC; //Device context of Bmp itemp : Integer; //for for cycle begin AssignFile(ReadFile, strFile); Reset(ReadFile); strItems := TStringList.Create; with strItems do while not eof(ReadFile) do begin Readln(ReadFile,strTemp); add(strTemp); end; CloseFile(ReadFile); //读取提示文件中的数据到strItems bmpShowText := TBitMap.Create; pDC := GetDc(pParent.handle); iLineHet := Get_LineHeight(pDC, bmpShowText.Canvas.Font.Height); with rectDraw do //rectDraw 矩形坐标(左上x,左下y,右上x,右下y) begin Top := 0; Left := 0; Right := pParent.Width; Bottom := iLineHet * strItems.Count + Height;//行高*行数+form高度 end; with bmpShowText do begin Height := rectDraw.Bottom+100;//图片高度 Width := rectDraw.Right; with Canvas do //canvas 画布 begin FillRect(rectDraw); Brush.Style:=bsClear; Font.Name := '宋体'; Font.Size := 10; end; end; rectTemp.Right := rectDraw.Right; rectTemp.Bottom := rectDraw.Bottom; rectTemp.Left := rectDraw.Left; iyPos := pParent.Top; for itemp := 0 to strItems.Count-1 do // 从0到行数 循环生成图片 begin rectTemp.Top := iyPos; rectTemp.Bottom := rectTemp.Top + iLineHet; //中对齐 //DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Center or Dt_Top); //左对齐 DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Left or Dt_Top); //右对齐 //DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Right or Dt_Top); Inc(iyPos, iLineHet); end; BitBlt(pDc, 0, 0, pParent.Width, pParent.Height, bmpShowText.Canvas.Handle, 0, pParent.Top, srcCopy); strItems.Free; //释放串strItems bmpShowText.Free; //释放图片资源 end;调用参数第一个是用于显示的Panel,第二个是字符文件 基本上算是Dx,自己看看吧
大家感觉一下,很简单 procedure TForm1.FormCreate(Sender: TObject); begin rv.TopMargin:=screen.Height; rv.BottomMargin:=screen.Height; rv.AddNL('我是中国人',1,1); rv.LoadText('1.txt',0,0,true); rv.VSmallStep := 1; rv.Format; end;procedure TForm1.Timer1Timer(Sender: TObject); begin if rv.VScrollPos<>rv.VScrollMax then rv.VScrollPos := rv.VScrollPos+1 else rv.VScrollPos := 0; end;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin if ord(key)=27 then close; end;
那请问如何用Image.Canvas.TextOut
能实现GDI输出显示吗?最好能给个范例谢谢!
直接canvas.textout(x,y,'aaaaaa')就行了//x,y为坐标在timer事件中重画就行了,别忘了将以前的画布抹掉clearcanvas()。否则就成花脸了
clearcanvas()如何调用?是否要输入坐标参数!请示范!
找到一个文字上升的DEMO文件,漂亮得很,不会闪烁!可惜原程序不知如何运行!老是报错!
谁教教我!
var
bmpShowText : TBitMap; //Bmp To Show
strTemp : String; //temp string for reading every line
ReadFile : TextFile; //Point to open the source text file
strItems : TStringList; //itemps of string list to save texts
rectDraw, rectTemp : TRect; //total rect for bmp & temp rect for every line
iyPos, iLineHet : Integer; //current y Pos to draw one line & line height
pDC : HDC; //Device context of Bmp
itemp : Integer; //for for cycle
begin
AssignFile(ReadFile, strFile);
Reset(ReadFile);
strItems := TStringList.Create;
with strItems do
while not eof(ReadFile) do
begin
Readln(ReadFile,strTemp);
add(strTemp);
end;
CloseFile(ReadFile); //读取提示文件中的数据到strItems bmpShowText := TBitMap.Create; pDC := GetDc(pParent.handle);
iLineHet := Get_LineHeight(pDC, bmpShowText.Canvas.Font.Height);
with rectDraw do //rectDraw 矩形坐标(左上x,左下y,右上x,右下y)
begin
Top := 0;
Left := 0;
Right := pParent.Width;
Bottom := iLineHet * strItems.Count + Height;//行高*行数+form高度
end;
with bmpShowText do
begin
Height := rectDraw.Bottom+100;//图片高度
Width := rectDraw.Right;
with Canvas do //canvas 画布
begin
FillRect(rectDraw);
Brush.Style:=bsClear;
Font.Name := '宋体';
Font.Size := 10;
end;
end; rectTemp.Right := rectDraw.Right;
rectTemp.Bottom := rectDraw.Bottom;
rectTemp.Left := rectDraw.Left;
iyPos := pParent.Top; for itemp := 0 to strItems.Count-1 do // 从0到行数 循环生成图片
begin
rectTemp.Top := iyPos;
rectTemp.Bottom := rectTemp.Top + iLineHet;
//中对齐
//DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Center or Dt_Top);
//左对齐
DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Left or Dt_Top);
//右对齐
//DrawText(bmpShowText.Canvas.Handle, pChar(strItems[itemp]), -1, rectTemp, Dt_Right or Dt_Top);
Inc(iyPos, iLineHet);
end;
BitBlt(pDc, 0, 0, pParent.Width, pParent.Height,
bmpShowText.Canvas.Handle, 0, pParent.Top, srcCopy); strItems.Free; //释放串strItems
bmpShowText.Free; //释放图片资源
end;调用参数第一个是用于显示的Panel,第二个是字符文件
基本上算是Dx,自己看看吧
这个控件还不错
如果感兴趣,大家到www.51delphi.com去下载一个最新的for d7吧
procedure TForm1.FormCreate(Sender: TObject);
begin
rv.TopMargin:=screen.Height;
rv.BottomMargin:=screen.Height;
rv.AddNL('我是中国人',1,1);
rv.LoadText('1.txt',0,0,true);
rv.VSmallStep := 1;
rv.Format;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
if rv.VScrollPos<>rv.VScrollMax then
rv.VScrollPos := rv.VScrollPos+1
else
rv.VScrollPos := 0;
end;procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if ord(key)=27 then
close;
end;