Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   [FillRect] Geht das schneller ? (https://www.delphipraxis.net/178365-%5Bfillrect%5D-geht-das-schneller.html)

EWeiss 3. Jan 2014 21:35


[FillRect] Geht das schneller ?
 
Delphi-Quellcode:
procedure TForm1.btnCaptureClick(Sender: TObject);
var
  Background: TBitmap;
  ARect: TRect;
  i: Integer;
  Left, Top: Integer;
begin

  Background := TBitmap.Create;
  Left := 0;
  Top := 0;
  try
    Background.Height := 48;
    Background.Width := 64;
    Background.Canvas.Brush.Style := bsSolid;
    Background.Canvas.Brush.Color := clfuchsia;
    ARect := Background.Canvas.ClipRect;
    Background.Canvas.FillRect(ARect);

    for i := 1 to 64 do
    begin
      ARect.Left := Left;
      ARect.Top := 0;
      ARect.Right := 1 + Left;
      ARect.Bottom := 1;

      Background.Canvas.Brush.Color := CaptureX.pTop[I].Color;
      Background.Canvas.FillRect(ARect);

      ARect.Left := Left;
      ARect.Top := 47;
      ARect.Right := 1 + Left;
      ARect.Bottom := 48;

      Background.Canvas.Brush.Color := CaptureX.pBottom[I].Color;
      Background.Canvas.FillRect(ARect);

      inc(Left);
    end;

    for i := 1 to 48 do
    begin
      ARect.Left := 0;
      ARect.Top := Top;
      ARect.Right := 1;
      ARect.Bottom := 1 + Top;

      Background.Canvas.Brush.Color := CaptureX.pLeft[I].Color;
      Background.Canvas.FillRect(ARect);

      ARect.Left := 64;
      ARect.Top := Top;
      ARect.Right := 63;
      ARect.Bottom := 1 + Top;

      Background.Canvas.Brush.Color := CaptureX.pRight[I].Color;
      Background.Canvas.FillRect(ARect);

      inc(Top);
    end;

  finally
    Background.SaveToFile('D:\Test.bmp');
    Background.Free;
  end;

end;
gibt es da eine schnellere Methode?

gruss

jaenicke 3. Jan 2014 21:40

AW: [FillRect] Geht das schneller ?
 
Ja, mit Scanline und pixelweisem Zugriff. Für die paar Pixel FillRect jeweils zu nutzen macht absolut keinen Sinn.

EWeiss 3. Jan 2014 21:42

AW: [FillRect] Geht das schneller ?
 
Zitat:

Zitat von jaenicke (Beitrag 1242013)
Ja, mit Scanline und pixelweisem Zugriff. Für die paar Pixel FillRect jeweils zu nutzen macht absolut keinen Sinn.

Kleines Beispiel?
Ich frage deshalb weil Scanline doch eigentlich ein Bild nach Pixeln untersucht oder?
Ich habe aber die Farben schon vorliegen eine nochmalige suche würde dann auch nichts beschleunigen.
Es wird ein Bild erstellt nicht ein vorhandenes auf Pixeln untersucht.


Es geht darum weil diese mit unter jede MS an eine Anwendung geschickt werden muss.
Da sollte das schon so schnell wie möglich sein.

gruss

jaenicke 3. Jan 2014 21:59

AW: [FillRect] Geht das schneller ?
 
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;

EWeiss 3. Jan 2014 22:04

AW: [FillRect] Geht das schneller ?
 
Werde ich mir mal anschauen .. Danke dir.

gruss

EWeiss 3. Jan 2014 22:14

AW: [FillRect] Geht das schneller ?
 
Wenn ich deine Function ersetze mit
Delphi-Quellcode:
CurrentPixelTop^ := i * 4 shl 16 + i * 4 shl 8 + i * 4;


meldet er mir
[DCC Fehler] Unit1.pas(166): E2010 Inkompatible Typen: 'tagRGBTRIPLE' und 'Integer'

Wo setze ich dann die TColor Farben bzw. weise die zu?
Sorry etwas undurchsichtig ..

gruss

Aphton 3. Jan 2014 22:19

AW: [FillRect] Geht das schneller ?
 
CurrentPixelTop ist ein Pointer auf ein TRGBTriple, nicht Integer!
Du weißt also durch die Dereferenzierung über ^ der linken Seite (TRGBTriple) ein Integer (rechte Seite) zu, was nicht geht!

EWeiss 3. Jan 2014 22:27

AW: [FillRect] Geht das schneller ?
 
Zitat:

Zitat von Aphton (Beitrag 1242025)
CurrentPixelTop ist ein Pointer auf ein TRGBTriple, nicht Integer!
Du weißt also durch die Dereferenzierung über ^ der linken Seite (TRGBTriple) ein Integer (rechte Seite) zu, was nicht geht!

Ah ok deshalb, war wohl ein Flüchtigkeit Fehler seitens jaenicke ;)
Kein Problem..

Verstehe aber immer noch nicht wo ich jetzt die Farben zuweisen soll.
Delphi-Quellcode:
CaptureX.pTop[I].Color;
gruss

jaenicke 3. Jan 2014 22:31

AW: [FillRect] Geht das schneller ?
 
Wenn du diese Variante benutzen willst, musst du die Variable logischerweise als PColor deklarieren. ;-)

// EDIT:
CaptureX.pTop[I].Color muss einfach immer dorthin wo jetzt die Farbwerte berechnet werden.
Delphi-Quellcode:
      Background.Canvas.Pixels[0, i] := CaptureX.pTop[I].Color;
...

Namenloser 3. Jan 2014 22:54

AW: [FillRect] Geht das schneller ?
 
Gerade ging es um Geschwindigkeit und jetzt lese ich Canvas.Pixels? :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:18 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz