Einzelnen Beitrag anzeigen

Benutzerbild von Zacherl
Zacherl

Registriert seit: 3. Sep 2004
4.629 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#23

AW: Optimierung von Pixel

  Alt 8. Apr 2016, 11:58
Mediums Funktion ist sogar LANGSAMER als Canvas.Pixels Mein Testcode
Delphi-Quellcode:
var
  B: TBitmap;
  X, Y: Integer;
  P: PRGBTriple;
  C: Cardinal;
begin
  B := TBitmap.Create;
  try
    B.PixelFormat := pf24Bit;
    B.Width := 2000;
    B.Height := 2000;
    // Canvas.Pixels
    C := GetTickCount;
    for Y := 0 to B.Height - 1 do
    begin
      for X := 0 to B.Width - 1 do
      begin
        B.Canvas.Pixels[X, Y] := clRed;
      end;
    end;
    ShowMessage(IntToStr(GetTickCount - C)); // 1141ms
    // Custom SetPixel method by Medium
    C := GetTickCount;
    for Y := 0 to B.Height - 1 do
    begin
      for X := 0 to B.Width - 1 do
      begin
        SetPixel(B, X, Y, clRed);
      end;
    end;
    ShowMessage(IntToStr(GetTickCount - C)); // 1391ms
    // Bitmap.ScanLine
    C := GetTickCount;
    for Y := 0 to B.Height - 1 do
    begin
      P := B.ScanLine[Y];
      for X := 0 to B.Width - 1 do
      begin
        P^.rgbtRed := 255;
        P^.rgbtGreen := 0;
        P^.rgbtBlue := 0;
        Inc(P);
      end;
    end;
    ShowMessage(IntToStr(GetTickCount - C)); // 15ms
  finally
    B.Free;
  end;
end;
produziert folgendes Ergebnis:
Code:
1141ms - Canvas.Pixels
1391ms - SetPixel by Medium
  15ms - ScanLine
Projekte:
- GitHub (Profil, zyantific)
- zYan Disassembler Engine ( Zydis Online, Zydis GitHub)

Geändert von Zacherl ( 8. Apr 2016 um 12:12 Uhr)
  Mit Zitat antworten Zitat