canvas教程

drawgrid画图之后图像闪动很严重,求指点

字号+ 作者:H5之家 来源:H5之家 2017-10-08 15:05 我要评论( )

php php爱好者 phpfans php教程 php入门 php源码 php动态 php基础 php进阶 php模板 php高级 smarty 数据库 mysql linux javascript ajax html css apache c c++

drawgrid画图之后图像闪动很严重,求指点

我用drawgrid学习制作一个表格工具,意图是通过拖拽工具栏里的人物一寸照片进入表格中可以实现动态排班的效果。
但是制作出来我发现了一个不知道怎么解决的情况就是,例如,我在表格第4列第一行拖入一个头像照片后,图像都剧烈的闪动。
我是基于五子棋程序的思想建立的,底层建立一个矩阵来控制drawgrid的,我检查了一下,发现矩阵的赋值没有任何问题。

请教delphi大师帮忙诊断一下会是哪里出了问题

  private
  Code:Array[0..16,0..5] of integer;
  { Private declarations }
  public
  { Public declarations }
  end;

var
  Form1: TForm1;
  Bmp1:TBitMap;
  Bmp2:TBitMap;
  Bmp3:TBitMap;
  Bmp4:TBitMap;
  D:integer;
  row:integer;
  col:integer;
  

implementation

uses Unit2;

......

procedure TForm1.DrawGrid1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
Accept:=True;
drawgrid1.MouseToCell(x,y,col,row);
statusBar1.Panels[1].Text:='col='+inttostr(col);
statusBar1.Panels[0].Text:='row='+inttostr(row);
end;

procedure TForm1.DrawGrid1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i,j:integer;
begin
if(Sender Is TDrawgrid) and (Source Is TSpeedbutton ) then
begin
drawgrid1.MouseToCell(x,y,col,row);
Code[row,col]:=D;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i,j: integer;
begin
D:=0;
for i:=1 to 16 do
  for j:=1 to 5 do
  begin
  Code[i,j]:=0;
  end;
Drawgrid1.OnDrawCell:= DrawGrid1DrawCell;
end;


procedure TForm1.SpeedButton1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
(Sender As TSpeedButton).BeginDrag(False);
D:=1;
end;

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
I:Integer;
begin
Bmp1:= SpeedButton1.Glyph;
Bmp2:= Form2.SpeedButton2.Glyph;
Bmp3:= Form2.SpeedButton3.Glyph;
Bmp4:= Form2.SpeedButton4.Glyph;

with (Sender as TDrawGrid) do
begin
Drawgrid1.ColWidths[0]:=20; //第一列大小
For I:= 1 to 17 do //第一列行序号
begin
if (ACol = 0)and(ARow = i) then
Drawgrid1.Canvas.TextOut(Rect.Left+1, Rect.Top+14, IntToStr(ARow))
end;
//第一行列标题
if (ACol = 1)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'A')
else if (ACol = 2)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'B')
else if (ACol = 3)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'C')
else if (ACol = 4)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'D')
else if (ACol = 5)and(ARow = 0) then
Drawgrid1.Canvas.TextOut(Rect.Left+27, Rect.Top+14, 'E')
else if (code[acol,arow]=0)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Invalidate //清空
else if (code[acol,arow]=1)and(ACol <> 0)and(ARow <> 0) then //成型
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp1)
else if (code[acol,arow]=2)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp2)
else if (code[acol,arow]=3)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp3)
else if (code[acol,arow]=4)and(ACol <> 0)and(ARow <> 0) then
Drawgrid1.Canvas.Draw(Rect.Left+10,Rect.Top,Bmp4)
end;
end;

end.

昵称: kalelshey  时间: 2011-08-29 10:15:34

闪烁产生一般都是刷新背景造成的。

你可以建立一个大的TBitmap对象,把你的图先画在TBitmap上面, 然后就bitblt到你显示的Canvas上面,就可以避免图像闪烁的问题。不要直接在显示的Canvas对象上直接画图。

用Drawgrid的话,处理游戏一类的情况还是不太合用的。

昵称: robotdeng  时间: 2011-09-26 18:55:40

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Developing realistic shaders in Arnold for Cinema 4d , Vol.

    Developing realistic shaders in Arnold for Cinema 4d , Vol.

    2017-09-19 11:03

  • html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开

    html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开

    2017-09-04 11:00

  • PHP课程体系.doc

    PHP课程体系.doc

    2017-07-31 10:00

  • 兄弟连PHP视频教程-canvas实例3-在线画图工具-形状工具课件

    兄弟连PHP视频教程-canvas实例3-在线画图工具-形状工具课件

    2017-07-30 16:01

网友点评