: : : : : : Hi,
: : : : : : This is my second try in this forum. I am trying to get the pixel information using C/C++(i.e. pixel values and RGB/Palette index values for bmp images.) Do we have any program/code for this? Any specific library that can be used on Windows platform? A piece of code would be of great help.
: : : : : : Thank You
: : : : : :
: : : : : :
: : : : : :
: : : : :
Simply draw bitmap in memory and use GetPixel() API.
: : : : :
: : : : : // Some pseudocode:
: : : : : HBITMAP hBitmap;
: : : : : // Load it ^^^ from disk or from resource in your EXE file
: : : : :
: : : : : HDC hScreenDC = GetDC (NULL);
: : : : : HDC hMemDC = CreateCompatibleDC (hScreenDC);
: : : : : HGDIOBJ hDefaultDCBmp = SelectObject (hMemDC, hBitmap);
: : : : : BITMAP bmInfo;
: : : : : COLORREF rgb;
: : : : : BYTE r,g,b;
: : : : :
: : : : : GetObject (hBitmap, sizeof (bmInfo), &bmInfo);
: : : : :
: : : : : for (int iRow=0; iRow < bmInfo.bmHeight; iRow++)
: : : : : {
: : : : : for (int iCol=0; iCol < bmInfo.bmWidth; iCol++)
: : : : : {
: : : : : rgb = GetPixel (hMemDC, iRow, iCol);
: : : : : r = GetRValue (rgb);
: : : : : g = GetGValue (rgb);
: : : : : b = GetBValue (rgb);
: : : : : // These ^^^ are your values?
: : : : : }
: : : : : }
: : : : :
: : : : : SelectObject (hMemDC, hDefaultDCBmp);
: : : : : DeleteDC (hMemDC);
: : : : : ReleaseDC (NULL, hScreenDC);
: : : : :
: : : : : DeleteObject (hBitmap);
: : : : : // Only do it ^^^ if you loaded BMP in that code,
: : : : : // if BMP was passed to you by some other code, do not call it.
: : : : : // That other code should be responsible for deleting it
: : : : :
: : : : :
To get the PALETTE info check MSDN:
: : : : : http://msdn2.microsoft.com/en-us/library/aa383686.aspx
: : : : :
: : : : : and check 'Bitmap' link.
: : : : :
: : : : :
: : : :
: : : :
: : : : That example is however for device dependant bitmaps which must be linked together with the program on placed in a DLL. To read/write a generic bitmap from the hd, you need to know about device independant bitmaps.
: : : :
: : :
To get HBITMAP from a HD file - simply call LoadImage() API.
: : :
: :
: :
: : But LoadImage wants a HINSTANCE and not a HANDLE? Will it work if you pass a HANDLE from CreateFile to it?
: :
:
http://msdn2.microsoft.com/en-us/library/ms648045.aspx
:
: When loading from file - HINSTANCE is NULL. Nice function: I use it to extend the functionality of a product. Say, you supply a few skins with the program. Put all skins into folder <Install dir>\Skins and load them at run-time. To add more skins experienced user will add more BMP files into that folder and product will automatically get more skins. In other words - do not use HINSTANCE of EXE file to keep resources.
:
Hmm... seems to be an undocumented feature. But then that wouldn't be the first time someone used that in the Win API :)
Sometimes you want to use custom bmp-files, sometimes you don't. If you want to descrease the number of files provided with the .exe, or if you don't want the stupid user to draw smileys all over your nice bitmaps, then you probably want to link them with the app.