Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.379 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: [FillRect] Geht das schneller ?

  Alt 3. Jan 2014, 21:59
Kleines Beispiel, mangels deiner Farbarrays einfach mit Graustufen als Beispielfarben:
Delphi-Quellcode:
var
  Background: TBitmap;
  ARect: TRect;
  CurrentPixelTop, CurrentPixelBottom: PRGBTriple;
  i, MostRightPixel: Integer;
begin
  Background := TBitmap.Create;
  try
    Background.PixelFormat := pf24bit;
    Background.Height := 48;
    Background.Width := 64;
    Background.Canvas.Brush.Style := bsSolid;
    Background.Canvas.Brush.Color := clFuchsia;
    ARect := Background.Canvas.ClipRect;
    Background.Canvas.FillRect(ARect);

    CurrentPixelTop := Background.ScanLine[0];
    CurrentPixelBottom := Background.ScanLine[Background.Height - 1];
    for i := 1 to Background.Width do
    begin
      CurrentPixelTop^.rgbtBlue := i * 4;
      CurrentPixelTop^.rgbtGreen := i * 4;
      CurrentPixelTop^.rgbtRed := i * 4;
      CurrentPixelBottom^ := CurrentPixelTop^;
      Inc(CurrentPixelTop);
      Inc(CurrentPixelBottom);
    end;

    MostRightPixel := Background.Width - 1;
    for i := 0 to Background.Height - 1 do
    begin
      Background.Canvas.Pixels[0, i] := i * 5 shl 16 + i * 5 shl 8 + i * 5;
      Background.Canvas.Pixels[MostRightPixel, i] := i * 5 shl 16 + i * 5 shl 8 + i * 5;
    end;
  finally
    Background.SaveToFile('c:\Temp\Test.bmp');
    Background.Free;
  end;
end;
// EDIT:
Alternativ, wenn du TColor-Werte direkt nutzen willst:
Delphi-Quellcode:
    Background.PixelFormat := pf32bit;
    [...]
    for i := 1 to Background.Width do
    begin
      CurrentPixelTop^ := i * 4 shl 16 + i * 4 shl 8 + i * 4;
      CurrentPixelBottom^ := CurrentPixelTop^;
      Inc(CurrentPixelTop);
      Inc(CurrentPixelBottom);
    end;
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!

Geändert von jaenicke ( 3. Jan 2014 um 22:03 Uhr)
  Mit Zitat antworten Zitat