Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between GetPixel and Canvas.Pixels in Delphi

Tags:

delphi

Is the Api Function "GetPixel" faster than Canvas.Pixels ?

like image 925
Mahmoud K. Avatar asked Mar 12 '10 09:03

Mahmoud K.


3 Answers

It should be the same:

function TCanvas.GetPixel(X, Y: Integer): TColor;
begin
  RequiredState([csHandleValid]);
  GetPixel := Windows.GetPixel(FHandle, X, Y);
end;
like image 122
Ritsaert Hornstra Avatar answered Nov 11 '22 08:11

Ritsaert Hornstra


If you are looking for something that performs better than GetPixel/Canvas.Pixel[] you should check out Bitmap.ScanLine. Only trouble is the data may be arranged in a number of ways, determined by Bitmap.PixelFormat

like image 37
Stijn Sanders Avatar answered Nov 11 '22 06:11

Stijn Sanders


The GetPixel function is very slow! If you need high (or even acceptable) performance, you should use the ScanLine property. ScanLine[y] is a pointer to the yth line of pixels in the bitmap, encoded in the format specified by the PixelFormat property. For instance, for a 24-bit bitmap, the line has the format

B1 G1 R1 B2 G2 R2 ... Bn Gn Rn

if the width of the bitmap is n. Bi, Gi, and Ri are the blue, green, and red intensities of pixel i, respectively, as bytes.

like image 2
Andreas Rejbrand Avatar answered Nov 11 '22 08:11

Andreas Rejbrand