Yo,

here's a code snippet of one of my PAQs. I combined it to a (hopefuly) working solution. See the complete code at

http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10056806

The GetPixel inline procedure is very fast and can be globalized. I hope you understand the way it works.

You can see the supported pixel formats in the case block of the function. The content of the resulting array can be interpreted depending on the color depth.

// code

type

TPixelMem : array[0..4] of Byte;

function MyGetPixel(X, Y : Integer; ABitmap : TBitmap): TPixelMem;

var SrcMem : PByteArray;

PixelSizeStep : Integer;

APixel : TPixelMem;

procedure GetPixel;

var Index, Helper : Integer;

begin

if PixelSizeStep = 4 then

begin

Helper := ((X - 1) div 2) + ((Y - 1) * ABitmap.Width div 2);

if ((X - 1) mod 2) = 0

then APixel[0] := ((15 shl 4) and (SrcMem[Helper])) shr 4

else APixel[0] := 15 and SrcMem[Helper];

end

else

begin

for Index := 0 to (PixelSizeStep div 8) - 1 do

begin

Helper := (X - 1) * (PixelSizeStep div 8) + (Y - 1) * ABitmap.Width * (PixelSizeStep div 8) + Index;

APixel[Index] := SrcMem[Helper];

end;

end;

end;

begin

case ABitmap.PixelFormat of

pf4bit : PixelSizeStep := 4;

pf8bit : PixelSizeStep := 8;

pf16bit : PixelSizeStep := 16;

pf24bit : PixelSizeStep := 24;

pf32bit : PixelSizeStep := 32;

end;

SrcMem := ABitmap.ScanLine[ABitmap.Height - 1];

GetPixel(X, Y);

Result := APixel;

end;

Hope this helps,

Slash/d003303

here's a code snippet of one of my PAQs. I combined it to a (hopefuly) working solution. See the complete code at

http://www.experts-exchang

The GetPixel inline procedure is very fast and can be globalized. I hope you understand the way it works.

You can see the supported pixel formats in the case block of the function. The content of the resulting array can be interpreted depending on the color depth.

// code

type

TPixelMem : array[0..4] of Byte;

function MyGetPixel(X, Y : Integer; ABitmap : TBitmap): TPixelMem;

var SrcMem : PByteArray;

PixelSizeStep : Integer;

APixel : TPixelMem;

procedure GetPixel;

var Index, Helper : Integer;

begin

if PixelSizeStep = 4 then

begin

Helper := ((X - 1) div 2) + ((Y - 1) * ABitmap.Width div 2);

if ((X - 1) mod 2) = 0

then APixel[0] := ((15 shl 4) and (SrcMem[Helper])) shr 4

else APixel[0] := 15 and SrcMem[Helper];

end

else

begin

for Index := 0 to (PixelSizeStep div 8) - 1 do

begin

Helper := (X - 1) * (PixelSizeStep div 8) + (Y - 1) * ABitmap.Width * (PixelSizeStep div 8) + Index;

APixel[Index] := SrcMem[Helper];

end;

end;

end;

begin

case ABitmap.PixelFormat of

pf4bit : PixelSizeStep := 4;

pf8bit : PixelSizeStep := 8;

pf16bit : PixelSizeStep := 16;

pf24bit : PixelSizeStep := 24;

pf32bit : PixelSizeStep := 32;

end;

SrcMem := ABitmap.ScanLine[ABitmap.H

GetPixel(X, Y);

Result := APixel;

end;

Hope this helps,

Slash/d003303