i'm trying build 2 functions for get and set pixles:
Code:
COLORREF GetDIBPixel(HDC hdcImage, long posX, long posY)
{
BITMAP structBitmapHeader;
memset( &structBitmapHeader, 0, sizeof(BITMAP) );
HBITMAP hBitmap =(HBITMAP) GetCurrentObject(hdcImage, OBJ_BITMAP);
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);
WORD wBmpWidth=structBitmapHeader.bmWidth;
WORD wBmpHeight=structBitmapHeader.bmHeight;
BYTE ImageData[(structBitmapHeader.bmBitsPixel % 8) - 1] [structBitmapHeader.bmWidth - 1] [structBitmapHeader.bmHeight - 1];
GetBitmapBits(hBitmap, structBitmapHeader.bmWidthBytes * structBitmapHeader.bmHeight, &ImageData);
COLORREF clrReturnColor=RGB(ImageData[2] [posX] [posY],ImageData[1] [posX] [posY],ImageData[0] [posX] [posY]);
return clrReturnColor;
}
void SetDIBPixel(HDC hdcImage, long posX, long posY, COLORREF clrNewColor)
{
BITMAP structBitmapHeader;
memset( &structBitmapHeader, 0, sizeof(BITMAP) );
HBITMAP hBitmap =(HBITMAP) GetCurrentObject(hdcImage, OBJ_BITMAP);
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);
WORD wBmpWidth=structBitmapHeader.bmWidth;
WORD wBmpHeight=structBitmapHeader.bmHeight;
BYTE ImageData[(structBitmapHeader.bmBitsPixel % 8) - 1] [structBitmapHeader.bmWidth - 1] [structBitmapHeader.bmHeight - 1];
GetBitmapBits(hBitmap, structBitmapHeader.bmWidthBytes * structBitmapHeader.bmHeight, &ImageData);
ImageData[2] [posX] [posY]=GetRValue(clrNewColor);
ImageData[1] [posX] [posY]=GetGValue(clrNewColor);
ImageData[0] [posX] [posY]=GetBValue(clrNewColor);
SetBitmapBits(hBitmap, structBitmapHeader.bmWidthBytes * structBitmapHeader.bmHeight, &ImageData);
}
but i get a memory leak.
can anyone advice me?