Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem in reading BMP Header

Problem in reading BMP Header

Scheduled Pinned Locked Moved C / C++ / MFC
questioniosdata-structureshelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Benjamin Bruno
    wrote on last edited by
    #1

    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

    L H C 3 Replies Last reply
    0
    • B Benjamin Bruno

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Benjamin Bruno

        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

        H Offline
        H Offline
        Heng Xiangzhong
        wrote on last edited by
        #3

        I have the same question, what is meaning of the program is not working. Be crashing or something else.

        1 Reply Last reply
        0
        • B Benjamin Bruno

          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

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          You know, the BITMAPFILEHEADER may be followed either by a BITMAPINFOHEADER or by a BITMAPV4HEADER or by a BITMAPV5HEADER structure, see the documentation[^].

          Veni, vidi, vici.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups