Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

GDI+ Performance Tipps

  Alt 23. Aug 2011, 18:11
Hallo,

Beschäftige mich seit ein paar Tagen etwas mit GDI+.

Mein Code ist momentan folgender:
(Nutze die GDI+ Library von http://www.bilsen.com/gdiplus/index.shtml)

Delphi-Quellcode:
type
 TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
    procedure FormCreate(Sender: TObject);
  private
    FAngle: Single;
    FBild1, FBild2: IGPBitmap;
    FBack: IGPBitmap;
  public
    { Public-Deklarationen }
  end;

implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
  FBild1 := TGPBitmap.Create('Background.jpg');
  FBild1.ConvertFormat(PixelFormat32bppPARGB,DitherTypeNone,PaletteTypeOptimal);
  FBild2 := TGPBitmap.Create('Typ.png');
  FBild2.ConvertFormat(PixelFormat32bppPARGB,DitherTypeNone,PaletteTypeOptimal);

  FBack := TGPBitmap.Create(Width,Height);
end;
Jetzt das eigentliche Zeichnen:

Delphi-Quellcode:
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
var Attr: IGPImageAttributes;
    Matrix: TGPColorMatrix;
    Graph1, Graph2: IGPGraphics;
begin
  // Zum Zeichnen auf das Offscreen-Bitmap
  Graph1 := TGPGraphics.Create(FBack);
  // Hintergrund malen
  Graph1.DrawImage(FBild1,0,0);
  
  // ColorMatrix initialisieren (--> Alpha Transparenz 60%)
  Matrix.SetToIdentity;
  Matrix.M[3,3] := 0.6;
  
  // Image-Attributes erstellen für Transparent-Color = Blau und Alpha Transparenz (s.o).
  Attr := TGPImageAttributes.Create;
  Attr.SetColorKey(TGPColor.Blue,TGPColor.Blue,ColorAdjustTypeBitmap);
  Attr.SetColorMatrix(Matrix,ColorMatrixFlagsDefault,ColorAdjustTypeBitmap);
  
  // Rotierendes, Alpha-Transparentes Bild mit Transparent-Color (blau) zeichnen
  Graph1.TranslateTransform(FBild2.Width / 2,FBild2.Height / 2);
  Graph1.RotateTransform(FAngle);
  Graph1.DrawImage(FBild2,-FBild2.Width / 2,-FBild2.Height / 2,
                   FBild2.Width,FBild2.Height,0,0,FBild2.Width,
                   FBild2.Height,TGPUnit.UnitPixel,Attr);
  Graph1.ResetTransform;

  // Zum Zeichnen des Offscreen-Bitmaps auf das Formular
  Graph2 := TGPGraphics.Create(Canvas.Handle);
  Graph2.DrawImage(FBack,0,0);

  FAngle := FAngle + 1;

  Done := false;
end;
Jetzt wäre meine Frage wie man da (und auch generell) noch ein paar FPS rauskitzeln kann.
Z.B. hat das setzen des Pixelformats der Bitmaps auf PixelFormat32bppPARGB die Framerate quasi verdoppelt.

Gibt es sonst noch irgendwelche Tricks?
Auch bzgl. Dingen, die in meinem Beispiel-Code vllt. nicht benutzt werden.

Gruß
Neutral General
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat