![]() |
[FillRect] Geht das schneller ?
Delphi-Quellcode:
gibt es da eine schnellere Methode?
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; gruss |
AW: [FillRect] Geht das schneller ?
Ja, mit Scanline und pixelweisem Zugriff. Für die paar Pixel FillRect jeweils zu nutzen macht absolut keinen Sinn.
|
AW: [FillRect] Geht das schneller ?
Zitat:
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 |
AW: [FillRect] Geht das schneller ?
Kleines Beispiel, mangels deiner Farbarrays einfach mit Graustufen als Beispielfarben:
Delphi-Quellcode:
// EDIT:
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; 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; |
AW: [FillRect] Geht das schneller ?
Werde ich mir mal anschauen .. Danke dir.
gruss |
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 |
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! |
AW: [FillRect] Geht das schneller ?
Zitat:
Kein Problem.. Verstehe aber immer noch nicht wo ich jetzt die Farben zuweisen soll.
Delphi-Quellcode:
gruss
CaptureX.pTop[I].Color;
|
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;
... |
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. |
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