Image Handling in C

Discussion in 'C' started by getbiplab, Sep 8, 2008.

  1. getbiplab

    getbiplab New Member

    Joined:
    Sep 8, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I have a .bmp image..I want to read the intensities of the pixels in a 2d array...how can i do that??plz help...
     
  2. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
  3. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    Here's an example program that displays the data for a 24-bit bitmap.
    (It will not work for bitmaps with a color palette.)
    Code:
    #include <stdio.h>
    #include <windows.h>
    
    int main()
    {
      BITMAPFILEHEADER bmfh;
      BITMAPINFOHEADER bmih;
      RGBTRIPLE rgbt;
      FILE *f;
      int i;
    
      f = fopen ("test.bmp", "rb");
    
      printf ("File Header\n");
      fread (&bmfh, sizeof(bmfh), 1, f);
      printf ("  Size     : %u\n", bmfh.bfSize);
      printf ("  OffBits  : %u\n", bmfh.bfOffBits);
    
      printf ("Info Header\n");
      fread (&bmih, sizeof(bmih), 1, f);
      printf ("  Size     : %u\n", bmih.biSize);
      printf ("  Width    : %u\n", bmih.biWidth);
      printf ("  Height   : %u\n", bmih.biHeight);
      printf ("  Planes   : %u\n", bmih.biPlanes);
      printf ("  BitCount : %u\n", bmih.biBitCount);
      printf ("  SizeImage: %u\n", bmih.biSizeImage);
      printf ("  ClrUsed  : %u\n", bmih.biClrUsed);
    
      printf ("RGB Triples\n");
      for (i = 0; i < bmih.biWidth * bmih.biHeight; ++i) {
        fread (&rgbt, sizeof(rgbt), 1, f);
        printf ("%02x %02x %02x\n",
                rgbt.rgbtRed, rgbt.rgbtGreen, rgbt.rgbtBlue);
      }
    
      fclose (f);
      return 0;
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice