Get pixel color with GetBitmapBits

Started by
1 comment, last by Bikonja 16 years, 7 months ago
Hi! I am a begginer in C++ builder, but I have started working on a plugin and I did manage to make some cool functions, but I have GetPixel and SetPixel too, which would be awesome if it weren't so slow... Btw, I am using only WinAPI functions to make the plugin much smaller (from aprox. 50 kb to aprox. 10 kb) so I would like it to stay that way... I was stumped with how to fix this so I asked how to fix this, what to do and I got this answer:
   HDC hDC,                  // Handle to the display device context
   hDCMem;               // Handle to the memory device context
   HBITMAP hBitmap;          // Handle to the new bitmap
   int iWidth, iHeight;      // Width and height of the bitmap
   int iDoneBits;	    // Changed bits
   int bitColorARRAY_SIZE;   // Size of the array
   int *bitColorARRAY_PTR;   // Pointer to the array with pixels
   // Retrieve the handle to a display device context for the client
   // area of the window.
   hDC = GetDC (hwnd);

   // Create a memory device context compatible with the device.
   hDCMem = CreateCompatibleDC (hDC);

   // Retrieve the width and height of window display elements.
   iWidth = GetSystemMetrics (SM_CXSCREEN) / 10;
   iHeight = GetSystemMetrics (SM_CYSCREEN) / 10;

   // Create a bitmap compatible with the device associated with the
   // device context.
   hBitmap = CreateCompatibleBitmap (hDC, iWidth, iHeight);

// HERE USE
    iDoneBits = SetBitmapBits(hBitmap, bitColorARRAY_SIZE, bitColorARRAY_PTR)

// HERE USE
// Insert code to use the bitmap.

   // Delete the bitmap object and free all resources associated with it.
   DeleteObject (hBitmap);

   // Delete the memory device context and the display device context.
   DeleteDC (hDCMem);
   DeleteDC (hDC);
I couldn't figure out this code completly... I have tried to implement it, but never succesfully... I understand some parts of the code, while I don't understand others... Some parts I understand, but I don't know how the code should look exactly... So could someone please explain some things to me? Why is iWidth and iHeight /10 and not just the function return value? Where do I use the MemoryDC? What I need to do with it? I know something about the lines need to be aligned and stuff, but I just can't seem to get it from everything I read on the net... So if someone would be please be so kind to try and explain this stuff a bit to me... How would I get a string in format "R,G,B" from an exact pixel... So let's say I want to get the color of the pixel on the screen with coordinates 20,53 and I need to get this in a string like "255,238,13"... How would I set a pixel like that? I am sorry I can't understand this code and I bug you, but for some reason I just can't seem to figure this code out... Thanx!
Advertisement
I am refreshing this topic since it has already fallen to the second page and no replies yet...

Please, if someone knows this stuff, help me understand it!
Does noone know this? Please, if someone does know this, please try explaining it to me so I understand and therefore can make this code work

This topic is closed to new replies.

Advertisement