Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Image Handling in C (http://www.go4expert.com/forums/image-handling-c-t13637/)

getbiplab 8Sep2008 22:10

Image Handling in C
 
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...

oogabooga 9Sep2008 01:33

Re: Image Handling in C
 
Look in the MSDN Bitmap reference.

oogabooga 9Sep2008 23:05

Re: Image Handling in C
 
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: c

#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;
}



All times are GMT +5.5. The time now is 23:58.