我在Image组件上绘图时,会出现不断闪动的情况,应该如何解决???(100分)

  • 主题发起人 主题发起人 hdqself2008
  • 开始时间 开始时间
H

hdqself2008

Unregistered / Unconfirmed
GUEST, unregistred user!
我在Image组件上绘图时,会出现不断闪动的情况,应该如何解决??
 
双缓冲
具体代码看看??
 
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(drawing)
{ posX=X;
posY=Y;
mousedown=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
drawing=true;
if(mousedown)
{
Image1->Canvas->Pen->Color=TColor(RGB(225,0,255));
Image1->Canvas->MoveTo(posX,posY);
Image1->Canvas->LineTo(X,Y);
posX=X;
posY=Y;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(drawing)
{Image1->Canvas->MoveTo(posX,posY);
Image1->Canvas->LineTo(X,Y);
posX=X;
posY=Y;
mousedown=false;
}
}
 
我用delphi, 一点也不闪啊
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Image1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
drawing: boolean;
mousedown: boolean;
posx, posy: integer;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if drawing then
begin
posX:=X;
posY:=Y;
mousedown:=true;
end;
end;

procedure TForm1.Image1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
drawing:=true;
if mousedown then
begin
Image1.Canvas.Pen.Color:=TColor(RGB(225,0,255));
Image1.Canvas.MoveTo(posX,posY);
Image1.Canvas.LineTo(X,Y);
posX:=X;
posY:=Y;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if drawing then
begin
Image1.Canvas.MoveTo(posX,posY);
Image1.Canvas.LineTo(X,Y);
posX:=X;
posY:=Y;
mousedown:=false;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
drawing:=false;
mousedown:=false;
end;

end.
 
打开双缓冲!将窗体的DoubleBuffered设为True
只要是VCL架构的 TForm,都有DoubleBuffered属性。
还闪的话,就用TPaintBox(这个有DoubleBuffered属性)或直接画到TForm的Canvas上,不要用TImage
 
我的TForm中没有DoubleBuffered属性啊。
TPaintBox是个组件吧,C++ Builder没自带这个组件
直接画到TForm的Canvas上,不要用TImage,的确不闪,但是不想那样做
 
如果绘的图不保存。直接在窗体上绘不闪烁
 
TPaintBox在system标签上阿,不过好像没有DoubleBuffered属性,反而Form中有该属性,但不在属性列表中,可以通过程序修改。
 
Form1.DoubleBuffered:=true,Form还有很多属性不是要写代码,不是用鼠标点的
 
我在初始化时加了Form1->DoubleBuffered=true;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Form1->DoubleBuffered=true;
}
结果在Image上绘图还是会闪的?
 
过来学习的
 
接受答案了.
 

Similar threads

回复
0
查看
815
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部