A bitmap is a pixel array. Each pixel corresponds to one element in the array be it a BYTE, WORD, or DWORD.
Here is code to read from a pixel array.
This will copy data from the image or screen to an array and write the array to disk. It also writes a small header to disk. Using this setup you can write as many chunks to the disk as you want. So you could store multiple images in the file this way.
void Copy32(DWORD *dwpSource,DWORD *dwpDest,DWORD dwSize);
void Copy32ASM(DWORD *dwpSource,DWORD *dwpDest,DWORD dwSize);
void Copy32(DWORD *dwpSource,DWORD *dwpDest,DWORD dwSize)
memcpy((DWORD *)dwpDest,(DWORD *)dwpSource,dwsize*sizeof(DWORD));
void Copy32ASM(DWORD *dwpSource,DWORD *dwpDest,DWORD dwSize)
//Allocate space for image in pixel array
DWORD *dwpPixelArray=new DWORD[size];
//If valid copy from image to pixel array
if (dwpPixelArray) Copy32ASM(dwpImage,dwpPixelArray,dwSize);
//Open a file
//Check for valid handle
//Write out header to disk
//Size in DWORDS, not bytes
//Write out data - size in total bytes
//Close the file
All the screen is, or any bitmap is, is an array of pixels. So it's just a memory to memory copy or bit block transfer - bitblt, or just a simple blit.
Sorry for using assembly, but this kind of programming task can really make use of the power of assembly to move large chunks of data from one memory location to another.
A linear array is the same as a 2D array conceptually and technically. The 2D portion is only a convention written into the compiler to make 2D arrays possible and flexible. But these are the same thing.
DWORD *map=new DWORD[width*height];
is the same as:
In fact the latter is exactly what the compiler does when you access a 2D array in the form map[x][y]. It auto-computes the correct offset in memory. I think linear arrays are much easier to work with personally.