Hi!
I'm trying to loop through pixels of a bitmap, check for their RGB values and add to a region if they match with a specified color.
All goes well and CombineRgn returns COMPLEXREGION (success) until line 138, pixel 514. The function returns ERROR on this and further pixels. I found out with GetLastError() that the error code is 6 (invalid handle). I don't get why it->second.regionHandle is invalid, because the debugger shows the exact same handle address for both- successful and unsuccessful calls to CombineRgn.Code:for(WORD y=0; y<wBmpHeight; y++) { for(WORD x=0; x<wBmpWidth; x++) { for(std::map<char*, CMould>::iterator it=moulds.begin(); it!=moulds.end(); it++) //this map holds 26 different color values and region handles { if(RGB(pPixels[p+2], pPixels[p+1], pPixels[p]) == it->second.trnsphRGB) { //if the colors match int iRes = CombineRgn(it->second.regionHandle, it->second.regionHandle, CreateRectRgn(x, y, x+1, y+1), RGN_XOR); //add this pixel to the region } } p+=3; } itoa(y, pOut, 10); //just to display the current y line SetWindowText(hwnd, pOut); }
The CMould class is nothing special, regionHandle is initialized in the constructor.
Header:
CPP:Code:#ifndef MOULD_H #define MOULD_H class CMould { public: CMould(COLORREF color, char** shouts); CMould(){} HRGN regionHandle; COLORREF trnsphRGB; char** pShouts; }; #endif
I can't think of what might be causing it.Code:#include "stdafx.h" CMould::CMould(COLORREF color, char** shouts) { trnsphRGB=color; memcpy(pShouts, shouts, sizeof shouts); regionHandle = CreateRectRgn(0, 0, 1, 1); }
Thanks for any help.



LinkBack URL
About LinkBacks




Thanks, it works flawlessly now, hadn't thought about deleting GDI objects before posting.