delphi中的双缓冲不足

问题描述 投票:0回答:1

我正在尝试使用Delphi XE2构建航空电子姿态指示器。

enter image description here

我正在将tRotateimage用于地平线http://www.delphiarea.com/products/delphi-components/rotateimage/

enter image description here

这是在常规图像后面,中间有透明的部分。

enter image description here

能够旋转图像以滚动并移动tRotateimage.top进行倾斜效果很好,但是在窗体上启用了双重缓冲后,出现了很多闪烁事件。当我旋转图像或通过.top

向上移动图像时,它会闪烁

还有其他方法可以消除这种闪烁吗?

 if tryStrToFloat(GetHashtag('#ROLL',',',Memo1.Lines.Text),MyDouble) then
 Begin
  rtAttitudeNeedle.Angle := 0- MyDouble;
  rtAttitude.Angle :=0- MyDouble;
 end;

 if tryStrToFloat(GetHashtag('#PITCH',',',Memo1.Lines.Text),MyDouble) then
 Begin
  rtAttitude.Top := Round(iAttitudeTop + MyDouble);
 end;
delphi flicker double-buffering
1个回答
0
投票

双重缓冲表单并不总是解决所有闪烁问题的魔术。您首先需要了解为什么会有这种闪烁。

如果您在绘制例程中直接使用画布对象很多,那么您什么都不做。

大多数时候需要解决这个问题并减少闪烁,您需要先绘制一个内存位图,然后最后将其绘制CopyRect到画布对象。

您的组件类似(用此代码替换Paint过程]

procedure TRotateImage.Paint;
var
  SavedDC: Integer;
  PaintBmp: TBitmap;
begin
  PaintBmp := TBitmap.Create;
  try
    PaintBmp.SetSize(Width, Height);

    if not RotatedBitmap.Empty then
    begin
      if RotatedBitmap.Transparent then
      begin
        PaintBmp.Canvas.StretchDraw(ImageRect, RotatedBitmap);
      end
      else
      begin
        SavedDC := SaveDC(PaintBmp.Canvas.Handle);
        try
          SelectClipRgn(PaintBmp.Canvas.Handle, ImageRgn);
          IntersectClipRect(PaintBmp.Canvas.Handle, 0, 0, Width, Height);
          PaintBmp.Canvas.StretchDraw(ImageRect, RotatedBitmap);
        finally
          RestoreDC(PaintBmp.Canvas.Handle, SavedDC);
        end;
      end;
    end;
    if csDesigning in ComponentState then
    begin
      PaintBmp.Canvas.Pen.Style := psDash;
      PaintBmp.Canvas.Brush.Style := bsClear;
      PaintBmp.Canvas.Rectangle(0, 0, Width, Height);
    end;

    Canvas.CopyRect(ClientRect, PaintBmp.Canvas, PaintBmp.Canvas.ClipRect);
  finally
    PaintBmp.Free;
  end;
end;

如果这不能完全解决问题,那么您可以看一下无闪烁的一组组件,并尝试调整您在其一个组件上拥有的旋转代码或从中继承代码(我不是作者,而是是声称具有无闪烁功能的一个)。

[FreeEsVclComponents GitHub存储库

© www.soinside.com 2019 - 2024. All rights reserved.