procedure BytesArrayToBitmap(const BytesArray: array of byte; const W, H: integer;
const PixelFormat: TPixelFormat; Bitmap: TBitmap);
var TBmp: TBitmap;
pX : ^byte;
LZ : integer;
begin
TBmp := TBitmap.Create;
try
case 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;
TBmp.PixelFormat := PixelFormat;
TBmp.Width := W;
TBmp.Height:= H;
pX := TBmp.ScanLine[TBmp.Height-1];
CopyMemory(pX, @BytesArray[0], LZ);
Bitmap.Assign(TBmp);
finally
TBmp.Free;
end;
end;