C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Please help me..... Posted by Gaurav_81ibm on 23 Jan 2007 at 4:36 AM
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


Report
Re: Please help me..... Posted by Lundin on 23 Jan 2007 at 5:19 AM
: 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
:
:


You will want to read about the "Device Indepentant Bitmap" (DIB) and Win API programming. Also, this topic was up here a couple of months ago:

http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=3&MsgID=349021

Report
Re: Please help me..... Posted by AsmGuru62 on 23 Jan 2007 at 5:22 AM
: 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.

Report
Re: Please help me..... Posted by Lundin on 23 Jan 2007 at 5:29 AM
: : 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.
Report
Re: Please help me..... Posted by AsmGuru62 on 24 Jan 2007 at 5:16 AM
: : : 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.
Report
Re: Please help me..... Posted by Lundin on 24 Jan 2007 at 5:36 AM
: : : : 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?
Report
Re: Please help me..... Posted by AsmGuru62 on 24 Jan 2007 at 9:13 PM
: : : : : 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.

Report
Re: Please help me..... Posted by Lundin on 25 Jan 2007 at 12:37 AM
: : : : : : 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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.