bolso
asked on
Bitmap files
How can i read each pixel of a Bitmap file, please give me some code?
In what language?
Probably C++, right? (I'm not totally stupid. I thought this was the window section.)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I would do is load the bitmap from the file using LoadImage(). Then you don't have to "parse" the information in the file (which can be done if you are interested in doing it that way.)
To load the image you would do.
HBITMAP ImgHnd = LoadImage(NULL,"c:\path\fi lename.bmp ",IMAGE_BI TMAP,0,0,L R_DEFAULTS IZE | LR_LOADFROMFILE);
This loads the image as a screen compatible bitmap. I'm assuming that is what you want. If you don't want it screen compatible it can be used to load a DIB bitmap.
continues.
To load the image you would do.
HBITMAP ImgHnd = LoadImage(NULL,"c:\path\fi
This loads the image as a screen compatible bitmap. I'm assuming that is what you want. If you don't want it screen compatible it can be used to load a DIB bitmap.
continues.
To read the pixels, you need to select the bitmap into a compatible device context. To do that you would do
HDC DCHnd = CreateDC("DISPLAY",NULL,NU LL,NULL);
HDC DCMem = CreateCompativleDC(DCHnd);
DeleteDC(DCHnd);
HBITMAP OldBitMap = SelectObject(DCMem,ImgHnd) ;// Select in image loaded from LoadImage().
// now use GetPixel() to get the pixels, like
COLOREF Color = GetPixel(DCMem,1,1);
DeleteDC(DCMem);
I hope this helps. Ask if you have questions.
HDC DCHnd = CreateDC("DISPLAY",NULL,NU
HDC DCMem = CreateCompativleDC(DCHnd);
DeleteDC(DCHnd);
HBITMAP OldBitMap = SelectObject(DCMem,ImgHnd)
// now use GetPixel() to get the pixels, like
COLOREF Color = GetPixel(DCMem,1,1);
DeleteDC(DCMem);
I hope this helps. Ask if you have questions.
I have to go, but If you want to quickly get the pixel information in an array. You can load the image as a DIB bitmap by specifying LR_CREATEDIBSECTION in the LoadImage() and then use GetDIBits() to get all the pixels at once.