There were questions about this topic from 2012 and 2015, saying that the raw file consisted of 12 bit header and following RGBA info for each pixel.
However, on Android 12, the output of "adb shell screencap -p" has changed and the beginning look like the following:
FF FE FD FF 50 00 4E 00 47 00 0D 00 0A 00 0D 00 ÿþýÿP�N�G�������
0A 00 1A 00 0D 00 0A 00 00 00 00 00 00 00 0D 00 ����������������
0A 00 49 00 48 00 44 00 52 00 00 00 00 00 07 00 ��I�H�D�R�������
FD FF 00 00 00 00 04 00 FD FF 08 00 06 00 00 00 ýÿ������ýÿ������
00 00 00 00 FD FF 24 00 7E 04 00 00 00 00 00 00 ����ýÿ$���������
01 00 73 00 52 00 47 00 42 00 00 00 FD FF FD FF ��s�R�G�B���ýÿýÿ
It starts with 0xFFFE (UTF-16 BOM) and has "PNG" and "sRGB" at the beginning, though it cannot be opened as a PNG file. How to convert this jumble of data to a proper image file?