Problem in reading BMP Header
-
Hi, I'm trying to read a BMP image, the code is as follows. If i'm using a value 820 as BMP_HEADER_SIZE, my program works fine. I tried calculating the BMP_HEADER_SIZE value by summing the size of structure tagBITMAPFILEHEADER and tagBITMAPINFOHEADER (from BMP header file) but the program is not working. How can i solve this? Class BlockinessProc. # define BMP_HEADER_SIZE 820 void ReadImage(const char* filename); char m_info[BMP_HEADER_SIZE]; unsignedchar** m_memblock; void Blockinessproc::ReadImage(const char* filename)// Reading a BMP Image { streampos size; ifstream inFile; inFile.open(filename, ios::in|ios::binary); if (inFile.is_open()) { inFile.seekg (0, ios::beg); long nHeaderSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); inFile.read ((char*)m_info, nHeaderSize); width = *(int*)&m_info[18]; //Getting Image width from Header height = *(int*)&m_info[22];// Getting Image height from Header long pos = inFile.tellg(); m_memblock = new uchar* [width]; m_memblock_out = new uchar* [width]; for (int i = 0; i < height; i++) // create new array size: height of image. { m_memblock[i] = new uchar [width*3]; m_memblock_out[i] = new uchar [width*3]; } int size_s = inFile.gcount(); inFile.seekg (pos); for(int i=0; i(m_memblock[i]), width*3); } inFile.close(); } } Thanks in Advance
-
Hi, I'm trying to read a BMP image, the code is as follows. If i'm using a value 820 as BMP_HEADER_SIZE, my program works fine. I tried calculating the BMP_HEADER_SIZE value by summing the size of structure tagBITMAPFILEHEADER and tagBITMAPINFOHEADER (from BMP header file) but the program is not working. How can i solve this? Class BlockinessProc. # define BMP_HEADER_SIZE 820 void ReadImage(const char* filename); char m_info[BMP_HEADER_SIZE]; unsignedchar** m_memblock; void Blockinessproc::ReadImage(const char* filename)// Reading a BMP Image { streampos size; ifstream inFile; inFile.open(filename, ios::in|ios::binary); if (inFile.is_open()) { inFile.seekg (0, ios::beg); long nHeaderSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); inFile.read ((char*)m_info, nHeaderSize); width = *(int*)&m_info[18]; //Getting Image width from Header height = *(int*)&m_info[22];// Getting Image height from Header long pos = inFile.tellg(); m_memblock = new uchar* [width]; m_memblock_out = new uchar* [width]; for (int i = 0; i < height; i++) // create new array size: height of image. { m_memblock[i] = new uchar [width*3]; m_memblock_out[i] = new uchar [width*3]; } int size_s = inFile.gcount(); inFile.seekg (pos); for(int i=0; i(m_memblock[i]), width*3); } inFile.close(); } } Thanks in Advance
Please edit your question and format you code by placing <pre> tags around it, so it is readable like:
streampos size;
ifstream inFile;inFile.open(filename, ios::in|ios::binary);
Also, and most important, please explain what "the program is not working" means.
-
Hi, I'm trying to read a BMP image, the code is as follows. If i'm using a value 820 as BMP_HEADER_SIZE, my program works fine. I tried calculating the BMP_HEADER_SIZE value by summing the size of structure tagBITMAPFILEHEADER and tagBITMAPINFOHEADER (from BMP header file) but the program is not working. How can i solve this? Class BlockinessProc. # define BMP_HEADER_SIZE 820 void ReadImage(const char* filename); char m_info[BMP_HEADER_SIZE]; unsignedchar** m_memblock; void Blockinessproc::ReadImage(const char* filename)// Reading a BMP Image { streampos size; ifstream inFile; inFile.open(filename, ios::in|ios::binary); if (inFile.is_open()) { inFile.seekg (0, ios::beg); long nHeaderSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); inFile.read ((char*)m_info, nHeaderSize); width = *(int*)&m_info[18]; //Getting Image width from Header height = *(int*)&m_info[22];// Getting Image height from Header long pos = inFile.tellg(); m_memblock = new uchar* [width]; m_memblock_out = new uchar* [width]; for (int i = 0; i < height; i++) // create new array size: height of image. { m_memblock[i] = new uchar [width*3]; m_memblock_out[i] = new uchar [width*3]; } int size_s = inFile.gcount(); inFile.seekg (pos); for(int i=0; i(m_memblock[i]), width*3); } inFile.close(); } } Thanks in Advance
I have the same question, what is meaning of the program is not working. Be crashing or something else.
-
Hi, I'm trying to read a BMP image, the code is as follows. If i'm using a value 820 as BMP_HEADER_SIZE, my program works fine. I tried calculating the BMP_HEADER_SIZE value by summing the size of structure tagBITMAPFILEHEADER and tagBITMAPINFOHEADER (from BMP header file) but the program is not working. How can i solve this? Class BlockinessProc. # define BMP_HEADER_SIZE 820 void ReadImage(const char* filename); char m_info[BMP_HEADER_SIZE]; unsignedchar** m_memblock; void Blockinessproc::ReadImage(const char* filename)// Reading a BMP Image { streampos size; ifstream inFile; inFile.open(filename, ios::in|ios::binary); if (inFile.is_open()) { inFile.seekg (0, ios::beg); long nHeaderSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); inFile.read ((char*)m_info, nHeaderSize); width = *(int*)&m_info[18]; //Getting Image width from Header height = *(int*)&m_info[22];// Getting Image height from Header long pos = inFile.tellg(); m_memblock = new uchar* [width]; m_memblock_out = new uchar* [width]; for (int i = 0; i < height; i++) // create new array size: height of image. { m_memblock[i] = new uchar [width*3]; m_memblock_out[i] = new uchar [width*3]; } int size_s = inFile.gcount(); inFile.seekg (pos); for(int i=0; i(m_memblock[i]), width*3); } inFile.close(); } } Thanks in Advance