Einzelnen Beitrag anzeigen

Satty67

Registriert seit: 24. Feb 2007
Ort: Baden
1.566 Beiträge
 
Delphi 2007 Professional
 
#10

AW: Zichenen sowie ab wann ist alles verfügbar?

  Alt 20. Mai 2011, 09:41
Eine bischen gespielt...
Delphi-Quellcode:
unit UPaintboxBuffer;

interface

uses
  ExtCtrls, Graphics;

type
  TPaintboxBuffer = class
  private
    FPaintBox : TPaintBox;
    FBitmapA,
    FBitmapB : TBitmap;
    FWorkBmp : TBitmap; // either FBitmapA or FBitmapB
    procedure CreateBitmap(var Bmp : TBitmap; W, H : Integer);
    procedure OnPaintHandler(Sender: TObject);
  public
    constructor Create(APaintBox : TPaintBox);
    destructor Destroy;
    procedure SwitchBitmap;
    property Bitmap : TBitmap read FWorkBmp;
  end;

implementation

constructor TPaintboxBuffer.Create(APaintBox : TPaintBox);
begin
  FPaintBox := APaintBox;
  CreateBitmap(FBitmapA, FPaintBox.Width, FPaintBox.Height);
  CreateBitmap(FBitmapB, FPaintBox.Width, FPaintBox.Height);
  FWorkBmp := FBitmapA;
  FPaintBox.OnPaint := OnPaintHandler;
end;

procedure TPaintboxBuffer.CreateBitmap(var Bmp : TBitmap; W, H : Integer);
begin
  Bmp := TBitmap.Create;
  Bmp.Width := W;
  Bmp.Height := H;
end;

destructor TPaintboxBuffer.Destroy;
begin
  FPaintBox.OnPaint := NIL;
  FBitmapA.Free;
  FBitmapB.Free;
end;

procedure TPaintboxBuffer.OnPaintHandler(Sender: TObject);
begin
  FPaintBox.Canvas.StretchDraw(FPaintBox.Canvas.ClipRect, FWorkBmp);
end;

procedure TPaintboxBuffer.SwitchBitmap;
begin
  if FWorkBmp = FBitMapA then
    FWorkBmp := FBitMapB
  else
    FWorkBmp := FBitMapA;
  FPaintBox.Invalidate;
end;

end.
Beispiel:
Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
var
  p : Pointer;
  s : String;
begin
  Timer1.Enabled := False;
  with PaintBoxBuffer do
  begin
    // Bitmap füllen
    p := Bitmap;
    s := DateTimeToStr(Now) +' Used Bitmap: $'+ IntToHex(Integer(p), 8);
    Bitmap.Canvas.FillRect(Bitmap.Canvas.ClipRect);
    Bitmap.Canvas.TextOut(10,10, s);
    // umschalten
    SwitchBitmap;
  end;
  Timer1.Enabled := True;
end;
Falls das nichts mit dem Ausgangs-Problem zu tun hat oder anderweitig unpassend ist... egal, hat mich von meiner regulären Arbeit abgehalten, wodurch sich das für mich schon gelohnt hat

Geändert von Satty67 (20. Mai 2011 um 09:44 Uhr)
  Mit Zitat antworten Zitat