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