I have read a BMP file into a byte array. So after looking into the answers of this question: byte array to int c++. Is this way of obtaining the widht and height from a BMP information header safe and correct?
long width, height;
memcpy(&width, &bmp[0x12], sizeof(long));
memcpy(&height, &bmp[0x16], sizeof(long));
And what problems could this approach bring?
long* width = (long*)(&bmp[0x12]);
long* height= (long*)(&bmp[0x16]);
According to Wikipedia BMP file format, 0x12
is the offset of the bitmap width in pixels, and 0x16
the offset of the bitmap height in pixels.
PD. I have found this solution for loading the bitmap from memory buffer but I want to keep the code simple because I only need the width, the height and the raw data of the bitmap, and I do not know if that answer is safe either.
Thanks!
See Question&Answers more detail:os