1、把image1.stretch:=true//为什么这样就不闪烁了?
在SETSTRETCH中有下面的过程调用,请看源码:
procedure TImage.PictureChanged(Sender: TObject);
var
G: TGraphic;
begin
if AutoSize and (Picture.Width > 0) and (Picture.Height > 0) then
SetBounds(Left, Top, Picture.Width, Picture.Height);
G := Picture.Graphic;
if G <> nil then
begin
if not ((G is TMetaFile) or (G is TIcon)) then
G.Transparent := FTransparent;
//如果STRETCH,重画时由IMAGE自己填充客户区,可减少闪烁;否则,由于
//图形可能没有完全覆盖客户区,重画时将自动填充客户区,引起闪烁。
if (not G.Transparent) and Stretch and not Proportional then
ControlStyle := ControlStyle + [csOpaque]
else // picture might not cover entire clientrect
ControlStyle := ControlStyle - [csOpaque];
if DoPaletteChange and FDrawing then Update;
end
else ControlStyle := ControlStyle - [csOpaque];
if not FDrawing then Invalidate;
end;
2、image1.Parent.DoubleBuffered:=true;//也就是双缓冲技术,可以理解
我的理解就是将图形先画到一个内部位图中,画图时将控件的HDC用内部位图
的HDC替代,用户将图形画到此位图中,WM_Paint消息重画时直接把位图在屏幕
上输出。
再贴代码,但这段代码我只明白个大概,跟我说的不一样,它是每次重画时直
接PAINT到位图上然后直接拷贝到屏幕上,并没有真正的缓冲起来:
procedure TWinControl.WMPaint(var Message: TWMPaint);
var
DC, MemDC: HDC;
MemBitmap, OldBitmap: HBITMAP;
PS: TPaintStruct;
begin
if not FDoubleBuffered or (Message. DC <> 0) then
begin
if not (csCustomPaint in ControlState) and (ControlCount = 0) then
inherited
else
PaintHandler(Message);
end
else
begin
DC := GetDC(0);
MemBitmap := CreateCompatibleBitmap(DC, ClientRect.Right, ClientRect.Bottom);
ReleaseDC(0, DC);
MemDC := CreateCompatibleDC(0);
OldBitmap := SelectObject(MemDC, MemBitmap);
try
DC := BeginPaint(Handle, PS);
Perform(WM_ERASEBKGND, MemDC, MemDC);
Message.DC := MemDC;
WMPaint(Message);
Message.DC := 0;
BitBlt(DC, 0, 0, ClientRect.Right, ClientRect.Bottom, MemDC, 0, 0, SRCCOPY);
EndPaint(Handle, PS);
finally
SelectObject(MemDC, OldBitmap);
DeleteDC(MemDC);
DeleteObject(MemBitmap);
end;
end;
end;
顺便说一下,刚才大富翁提交失败,害我白敲半天,改在NOTEPAD里重敲一把,真火。