I'm using DIB image manipulation for some of the graphics manipulation routines in my game's engine, and I need to pass an array of bytes to a function. This array's values are then modified, and then the SetDIBitsToDevice API call is used to send the bitmap back to the target Device Context. The problem I ran into was simple, I'm new to C++ and have been using VB for a VERY long time, so pointers are new to me. How do I use a pointer to pass the array to the function, and then how do i manpulate values in the array? here's an example of what I'm trying to do, note that this is not the actual code but it shows how i tried to use the array.
void myroutine (HDC hDestDC, BITMAPINFO *biSrcInfo, char *bBytes[]) {
//bBytes is a pointer to the array of bytes.
// THE BELOW CODE WOULD NORMALLY BE IN A FOR LOOP...
//in this example we basically set the pixel color of the bottom-left most pixel of the bitmap.
bBytes = BLUE_VALUE //set array element 0
++bBytes = GREEN_VALUE //set array element 1
++bBytes = RED_VALUE //set array element 2
}
Ok, well thats how i've been trying to change values in my byte-array, but i aint even sure if thats the problem, my program causes a fatal error when i call this function, and this may be where the real problem is - when i call SetDIBitsToDevice I dont know if I'm passing the pointer to the array correctly. In one example on CodeGuru.com I saw them call the SetDIBitsToDevice function as follows:
// Let's draw the grayscale image
LPVOID lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);
::SetDIBitsToDevice(pDC->m_hDC, xDest, yDest, nWidth, nHeight, 0, 0, 0,
nHeight, lpDIBBits, (LPBITMAPINFO)hDIB, DIB_RGB_COLORS);
Someone help, maybe provide a solid example of howto do this. Do i need to somehow convert my array of bytes to LPVOID? and if so, HOW? NOTE that I originally wrote this routine in VB but am now converting it to C++, it worked fine in VB, I am like 99% sure my problem has something to either do with my handleing of the pointers to the arrays, and manipulating the array element values, OR me trying to pass *bBytes to the SetDIBitsToDevice API Call...
[edited by - Timbo_M45 on October 3, 2002 11:10:48 AM]