One tiny typo, in @Shock451 answer.
According to: https://en.wikipedia.org/wiki/BMP_file_format the values of BITMAPFILEHEADER and BITMAPINFOHEADER are swapped.
there Should be:
// since BITMAPFILEHEADER = 14 and BITMAPINFOHEADER = 40
not:
// since BITMAPFILEHEADER = 40 and BITMAPINFOHEADER = 14