Need to load a bmp and read pixel rgba values
I'm trying to find a library or sample code that loads a bmp, and lets me read pixel values with a simple function call. Are there any libraries or example code that does this? I've been looking at OpenIL/DevIl, but I can't find a function that lets me read a single pixel.
Thanks.
-Nick
GDI will, you will have a hard time reading an alaph channel from a bmp however:) MFC has the CBitmap class that will allow you to get a pointer to the raw bits as well.
Cheers
Chris
Cheers
Chris
Intel has a freely available image library. I don't remember teh name. There must be tones of code out there.
Hmm how about googleing loading bitmaps source code:)
You need to do some work on your own;)
CHeers
Chris
Hmm how about googleing loading bitmaps source code:)
You need to do some work on your own;)
CHeers
Chris
FILE * f = fopen("filename", "rb");BITMAPFILEHEADER fh;BITMAPINFOHEADER ih;fread(&fh, sizeof(BITMAPFILEHEADER), 1, f);fread(&ih, sizeof(BITMAPINFOHEADER), 1, f);unsigned char * pixels = (unsigned char *)malloc(ih.biWidth * ih.biHeight * ih.biBitCount / 8);unsigned int linewidth = ih.biWidth * ih.biBitCount / 8;unsigned int padwidth = ((((ih.biWidth * ih.biBitCount / 8) >> 2) + 1) << 2) - linewidth;unsigned int fullwidth = linewidth + padwidth;for (int c = 0; c < ih.biHeight; c ++){ fread(&(pixels + (c * fullwidth)), sizeof(unsigned char), linewidth, f); fseek(f, padwidth, SEEK_CUR); }// your data is stored in pixels
This will only work for single plane 24 bit bitmap files! To make it compatible for all sorts of bitmaps, youll have to look up the information by yourself. And as you can see, there is no error checking in there.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement