tags:

views:

385

answers:

3

Hey,

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

+4  A: 

It should be the same:

function TCanvas.GetPixel(X, Y: Integer): TColor;
begin
  RequiredState([csHandleValid]);
  GetPixel := Windows.GetPixel(FHandle, X, Y);
end;
Ritsaert Hornstra
+2  A: 

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

Stijn Sanders
A: 

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.

Andreas Rejbrand
May I ask what is wrong with my argument?
Andreas Rejbrand
@Ritsaert: Are you sure? I just created a small BMP file filled with (R, G, B) = (0xFF, 0, 0) and looked at it in the memory. See http://privat.rejbrand.se/hex.png. The highlighted byte is the first byte of the first scanline. To me it sure looks like the bytes go BBGGRRBBGGRR...
Andreas Rejbrand
@Andreas: I am ashamed. You are correct. The format for the 24 bit bitmaps is in BGR order.
Ritsaert Hornstra