d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Win32 Api And Windows Gdi > I Doubt This Exists
Prev123457Next
Add Reply New Topic New Poll
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 10 2009 01:13pm
Quote (ASBands @ 10 Nov 2009 07:35)
I would imagine GetBitmapBits (http://msdn.microsoft.com/en-us/library/dd144850(VS.85).aspx) would be more useful.


Doesn't help me at all. Nothing to modify, or iterate through, or compare with any predefined function.

http://www.experts-exchange.com/Programming/System/Windows__Programming/MFC/Q_11962418.html - That is probably the closest thing to something useful I've googled so far.

http://cboard.cprogramming.com/windows-programming/87826-getting-bitmaps-buffer.html
http://cboard.cprogramming.com/windows-programming/64167-processing-bitmap-data.html#post456766

http://www.codeproject.com/KB/graphics/BitmapCompare.aspx

This post was edited by Muted on Nov 10 2009 01:36pm
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Nov 10 2009 02:31pm
Quote (Muted @ Nov 10 2009 02:13pm)
Doesn't help me at all. Nothing to modify, or iterate through, or compare with any predefined function.

How not? That function copies the values of an HBITMAP to some array you own, at which point you can do whatever comparisons you want.

And those links you posted...the first one (Experts Exchange) has an answer: use GetBitmapBits. The second one has an answer: use GetBitmapBits. The third suggests GetDIBits, which is the new version of GetBitmapBits. The fourth uses GetDIBits, which is the new version of GetBitmapBits. None of these compare with a pre-defined function because that's not what GDI+ is for. It's a graphics library, not an analysis or computer vision library.

This post was edited by ASBands on Nov 10 2009 02:43pm
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 10 2009 05:27pm
My best guess so far:

Code
int main() {

   AllocConsole();
   HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);

   while (true) {
       Sleep(50);

       if (GetAsyncKeyState(VK_HOME)) {
           HDC hDc = CreateCompatibleDC(0);
           HBITMAP hBmp = CreateCompatibleBitmap(hDc, 50, 50);
           SelectObject(hDc, hBmp);

           SIZE Temp;
           GetBitmapDimensionEx(hBmp, &Temp);

           long ImageSize = Temp.cx * Temp.cy; // is 0 somehow
           long *MyImage;
           GetBitmapBits(hBmp, ImageSize, MyImage);

           char ImagePixel[500] = {'\0'};
           sprintf(ImagePixel, "Image size: %d\n", ImageSize);
           WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);

           for (int x = 0; x < ImageSize; x++) {
               sprintf(ImagePixel, "%d\n", MyImage[x]);
               WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
           }

           BitBlt(GetDC(0), 300, 300, 300, 300, GetDC(0), 0, 0, SRCCOPY); // Copies the image to the monitor, works fine
           DeleteObject(hBmp);
       }

       if (GetAsyncKeyState(VK_END)) { exit(0); }
   }

   return 0;
}


Still unable to modify anything, or even see the bitmap's data itself.

Oh, that's why it returns 0, thank you M$!
http://www.vbforums.com/archive/index.php/t-15512.html

Well, this does me absolutely no fucking good.

This post was edited by Muted on Nov 10 2009 05:40pm
Member
Posts: 5,219
Joined: Oct 29 2009
Gold: 0.00
Warn: 20%
Nov 10 2009 07:57pm
Quote (Muted @ Nov 10 2009 04:27pm)
My best guess so far:

Code
int main() {

  AllocConsole();
  HANDLE outHandle = GetStdHandle(STD_OUTPUT_HANDLE);

  while (true) {
      Sleep(50);

      if (GetAsyncKeyState(VK_HOME)) {
          HDC hDc = CreateCompatibleDC(0);
          HBITMAP hBmp = CreateCompatibleBitmap(hDc, 50, 50);
          SelectObject(hDc, hBmp);

          SIZE Temp;
          GetBitmapDimensionEx(hBmp, &Temp);

          long ImageSize = Temp.cx * Temp.cy; // is 0 somehow
          long *MyImage;
          GetBitmapBits(hBmp, ImageSize, MyImage);

          char ImagePixel[500] = {'\0'};
          sprintf(ImagePixel, "Image size: %d\n", ImageSize);
          WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);

          for (int x = 0; x < ImageSize; x++) {
              sprintf(ImagePixel, "%d\n", MyImage[x]);
              WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
          }

          BitBlt(GetDC(0), 300, 300, 300, 300, GetDC(0), 0, 0, SRCCOPY); // Copies the image to the monitor, works fine
          DeleteObject(hBmp);
      }

      if (GetAsyncKeyState(VK_END)) { exit(0); }
  }

  return 0;
}


Still unable to modify anything, or even see the bitmap's data itself.

Oh, that's why it returns 0, thank you M$!
http://www.vbforums.com/archive/index.php/t-15512.html

Well, this does me absolutely no fucking good.


Quit bitching and use another API.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 10 2009 10:57pm
Quote (infinitesimal @ 10 Nov 2009 20:57)
Quit bitching and use another API.


I don't believe this thread was named "General Chat," take it else where.
If you have something to contribute other than worthless opinions that are off-topic, post.

Code
BITMAP bmpOrig;
   GetObject(hBmp, sizeof(BITMAP), &bmpOrig);
   int sizeOrig = bmpOrig.bmWidthBytes * bmpOrig.bmHeight;
   BYTE* pDataOrig = new BYTE[sizeOrig];
   GetBitmapBits(hBmp, sizeOrig, pDataOrig);
   SelectObject(hDc, hBmp);

   char ImagePixel[500] = {'\0'};
   sprintf(ImagePixel, "Image size: %d\n", sizeOrig);
   WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);

   for (int x = 0; x < sizeOrig; x++) {
       sprintf(ImagePixel, "pDataOrig[%d]: %d\n", x, pDataOrig[x]);
       WriteConsole(outHandle, ImagePixel, strlen(ImagePixel), NULL, NULL);
   }


Does absolutely nothing. There's 399 empty (value of 0) bytes in the array pDataOrig.

BITMAP structure:http://msdn.microsoft.com/en-us/library/dd183371(VS.85).aspx
Quote
typedef struct tagBITMAP {
  LONG  bmType;
  LONG  bmWidth;
  LONG  bmHeight;
  LONG  bmWidthBytes;
  WORD  bmPlanes;
  WORD  bmBitsPixel;
  LPVOID bmBits;
}BITMAP, *PBITMAP;


That does me no good, because how it's capturing the image from the screen (device context *) is using a "BITMAP HANDLER" HBITMAP.
If I wanted to, I suppose I could save the image that's being captured to the harddrive (.../temp.bmp), then compare it with another *.bmp.
This shows the structure of a bitmap image: http://msdn.microsoft.com/en-us/library/dd183391(VS.85).aspx which would simplify a lot.

'Side from all that, I still don't know how to load an image from the harddrive. There's only examples that I've seen that load it from a resource file, and that's just not acceptable.
That'd cause an extremely large *.exe file and lose the ability of viewing/editing/adding images to a folder, which is a complete no-no for what I'm aiming for here.

"Memory Device Contexts" - MSDN -http://msdn.microsoft.com/en-us/library/dd145049(VS.85).aspx
Quote
The memory DC stores bitmap images for a particular device. An application can create a memory DC by calling the CreateCompatibleDC function.

The original bitmap in a memory DC is simply a placeholder. Its dimensions are one pixel by one pixel. Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the DC by calling the SelectObject function. To create a bitmap of the appropriate dimensions, use the CreateBitmap, CreateBitmapIndirect, or CreateCompatibleBitmap function. After the bitmap is selected into the memory DC, the system replaces the single-bit array with an array large enough to store color information for the specified rectangle of pixels.


This post was edited by Muted on Nov 10 2009 11:27pm
Member
Posts: 6,493
Joined: Apr 5 2006
Gold: 804.88
Nov 11 2009 05:44am
What about:

Code
HBITMAP hBMP;              // Handle Of The Bitmap
BITMAP BMP;              // Bitmap Structure
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), szFileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );

char achError[200];
if (!hBMP)               // Does The Bitmap Exist?
{
 
 MessageBox(hWnd, szFileName ,"Failed to load Bitmap", MB_OK);
 sprintf_s(achError, 200, "Couldn't find parameter '%s'",szFileName);
 return FALSE;             // If Not Return False
}
sprintf_s(achError, 200, "TEXTURE LOADED: '%s'",szFileName);

GetObject(hBMP, sizeof(BMP), &BMP);         // Get The Object
                 // hBMP:        Handle To Graphics Object
                 // sizeof(BMP): Size Of Buffer For Object Information
                 // &BMP:        Buffer For Object Information


Hmm, that isn't loading it into an array though. >_< I've done this before. If only I can find the code...

Actually, nevermind. You can access the array using BMP.bmBits.

This post was edited by Vio-Lewis on Nov 11 2009 05:49am
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Nov 11 2009 01:23pm
First off, HBITMAP is not a "bitmap handler," it represents a handle to a bitmap. The semantics of those things are completely different.

Anyway, if you want to load an image from disk, there are a million ways to do that (not through Windows libraries -- that's not what they are for). Bitmaps are easy, just parse the header for information (http://en.wikipedia.org/wiki/BMP_file_format) and the data is the remainder of the file's characters in row-major order. JPEG, PNG and other file formats are a little bit more difficult, so I'd suggest a library like CImg (http://cimg.sourceforge.net/). Once you have it loaded, just blit it to your target to draw it.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 11 2009 03:47pm
Quote (ASBands @ 11 Nov 2009 14:23)
First off, HBITMAP is not a "bitmap handler," it represents a handle to a bitmap.  The semantics of those things are completely different.

Anyway, if you want to load an image from disk, there are a million ways to do that (not through Windows libraries -- that's not what they are for).  Bitmaps are easy, just parse the header for information (http://en.wikipedia.org/wiki/BMP_file_format) and the data is the remainder of the file's characters in row-major order.  JPEG, PNG and other file formats are a little bit more difficult, so I'd suggest a library like CImg (http://cimg.sourceforge.net/).  Once you have it loaded, just blit it to your target to draw it.


Looks like I'll just be using a resource file and loading it specifically from the compiled *.exe itself then, thanks anyways.
But that doesn't... Well, actually, I guess after I load the resource file, I can use that CompareBitmaps function I found and see if they're a match or not.
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 11 2009 06:35pm
Quote (ASBands @ 11 Nov 2009 14:23)
Anyway, if you want to load an image from disk, there are a million ways to do that (not through Windows libraries -- that's not what they are for).


Correct me if I'm wrong when I say this: Window's GDI/GDI+ is owned by Microsoft, and is therefore a "Window's library" correct?

http://msdn.microsoft.com/en-us/library/ms534420(VS.85).aspx
Bitmap::FromFile The FromFile method creates a Bitmap object based on an image file.

Thank you for the mis leading information, again.
It was extremely helpful in helping me, help myself, as usual
And also, prove people to be incorrect along the way, but that's just me.

This post was edited by Muted on Nov 11 2009 06:36pm
Member
Posts: 31,680
Joined: Nov 10 2007
Gold: 1.00
Nov 11 2009 07:27pm
After even more googling, searching, and asking questions without any replies:
Window's GDI+ has a class named "Bitmap" that has this: http://msdn.microsoft.com/en-us/library/ms534420(VS.85).aspx
Window's GDI? (Win32 and COM Development) has a function called LoadImage() apparently: http://msdn.microsoft.com/en-us/library/ms648045(VS.85).aspx

This post was edited by Muted on Nov 11 2009 07:33pm
Go Back To Programming & Development Topic List
Prev123457Next
Add Reply New Topic New Poll