type
TBytesDynArray = array of byte;
procedure BitmapToBytesArray(Bitmap: TBitmap; var BytesArray: TBytesDynArray);
var pX : ^byte;
N,LZ : integer;
begin
case Bitmap.PixelFormat of
pf8bit : LZ := (Bitmap.Width * Bitmap.Height);
pf16bit: LZ := (Bitmap.Width * Bitmap.Height) * 2;
pf24bit: LZ := (Bitmap.Width * Bitmap.Height) * 3;
pf32bit: LZ := (Bitmap.Width * Bitmap.Height) * 4;
end;
pX := Bitmap.ScanLine[Bitmap.Height-1];
SetLength(BytesArray, LZ);
CopyMemory(@BytesArray[0], pX, LZ);
end;
exemple :
var
BA : TBytesArray;
begin
BitmapToBytesArray(ImageX.Picture.Bitmap, BA);
...
end;