I try to initialize the data for the bitmap image (header info and pixels bits ) through the following function:
VOID MakeBitmap (BITMAPINFO* info, BYTE *bits, int w, int h) { info = (BITMAPINFO*)new BYTE[w * h * 3 + sizeof(BITMAPINFOHEADER)]; ZeroMemory(info, w * h * 3 + sizeof(BITMAPINFOHEADER)); BITMAPINFOHEADER* ph = &info->bmiHeader; ph->biSize = sizeof(BITMAPINFOHEADER); ph->biWidth = w; ph->biHeight = h; ph->biPlanes = 1; ph->biBitCount = 24; ph->biSizeImage = w * h * 3; bits = (BYTE*)info + sizeof(BITMAPINFOHEADER); } Initializing everything is fine. But as soon as I try to get access to the element of the array bits[i] , the program crashes as if there is nothing there. It also does not work if you allocate a separate memory block for bits .
What is the problem?
bits, and what is passed to the function does not change - check it yourself using a debugger or debug output of the contents of variables. Business for 5 minutes. Theinfois the same. There are two solutions. Both lead to a change in the prototype f-tion:VOID MakeBitmap (BITMAPINFO** info, BYTE** bits, int w, int h)orVOID MakeBitmap (BITMAPINFO*& info, BYTE*& bits, int w, int h)And specify what are in-parameters, and what is out. - gecube