Is there a way of finding the height and width from the *.bmp file either through its header file or another way? I'm currently using Visual Studio 2010.
The plan is to slightly alter the code above to dynamically allocate a 1D array but using the width and height. I am posting the code intended to use but I firstly need to obtain the height and width of the image.
int width, height; // width and height of image
int offset = 0; // num of elements traversed in array
int value = 0; // image intensity value
unsigned byte* array_1D = NULL; // Pointer to unsigned byte
dynamic allocation array_1D = new unsigned byte[height*width];
if(array_1D == NULL) return; // return if memory not allocated
for(int j=0; j<height; j++) // traverse height (or rows)
{
offset = width * j; // modify offset travelled
for(int i=0; i<width; i++) // traverse width (or columns)
{
// update value at current index i.e. (offset+i)
array_1D[offset + i] = value++;
}
value = 0;
}
//delete the memory dynamically allocated
delete[] array_1D;
Search on wiki BMP file format , look at the picture . Images , audios , videos, contains headers at the beggining . Depending on the format , the size of the header (in bytes) is fixed. Bitmap can be read as text file , but I suggest you to start reading binary file , since bitmap are big.
Bitmaps are binary files. Reading them as text can lead to incorrectly read data and damaged image as a result. It takes a a single sequence of 0x0D 0x0A for everything to break.