Finally, I found the reason of my troubles.
The size of Canvas is lost after passing it through TMemoryStream (because of transparency).
//now Canvas.Width and Canvas.Height are set to some size
memStream:=TMemoryStream.Create;
try
BMP.SaveToStream(memStream);
memStream.Position:=0;
BMP.LoadFromStream(memStream);
finally
memStream.Free;
//now Canvas.Width and Canvas.Height are 0
But the size of Canvas is restored after some operation.
Therefore I had to do twice:
BMP.Canvas.Clear;
BMP.Canvas.Clear;
//OR
BMP.Canvas.FillRect(0, 0, BMP.Canvas.Width, BMP.Canvas.Height);
BMP.Canvas.FillRect(0, 0, BMP.Canvas.Width, BMP.Canvas.Height);
but this works immediately:
BMP.Canvas.FillRect(0, 0, BMP.Width, BMP.Height);