Click to See Complete Forum and Search --> : Get pixel color with GetBitmapBits


Bikonja
September 4th, 2007, 05:24 AM
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 they 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!

Bikonja
September 6th, 2007, 05:32 AM
Does noone know how to explain this?
Please, if someone knows this stuff, could you please explain it to me so I understand it and therefore know how to make this work?

Krishnaa
September 6th, 2007, 05:38 AM
Is this is code you wrote or you got from somewhere ? What exactly is your requirement ?

Bikonja
September 6th, 2007, 05:48 AM
Yes, I got it from somewhere...
I need to make the code that does exactly what SetPixel and GetPixel does, but does it faster... I've been given this code for that task, but even though I've been reading about all this everywhere I could find stuff, I just can't seem to get this code fully so I could fix it to work... Currently, I could get it to get some return value, but it was not right, and since not everything here is clear to me, I don't know if I made something really stupid or what... I don't ask for the complete code, but I would really like someone to explain this to me so I understand it... I want to learn how to do it myself too, not just make this (although I would also like to make this function as soon as I can, but it's better for me to learn to do it myself)....
So what I want is if someone can please explain every part of this code what it does and what it is needed for and the syntax and how to use it and stuff.... I don't know much of C++ but I do know programming in general, however, I still can't figure out this code and that's why I am asking for help.... Please!

Bikonja
September 6th, 2007, 03:07 PM
Well? Can anyone help me?
Or point me to another place where I can seek help?
If you need more questions answered just ask....