Thank you!
Member 9255349
Posts
-
Accessing Pixels with CreateDIBSection -
Accessing Pixels with CreateDIBSectionThanks so much for the quick reply. You are a lifesaver! (Or... at least a sleep saver.) :)
-
Accessing Pixels with CreateDIBSectionHello all. I am new to image processing and am having trouble with CreateDIBSection. I have been reading other threads on this topic and code snippets for several days now, so I was hoping at this point to get specific help with my code rather than a link to a previous explanation or code. I have a dialog based app. I want to take a screen shot, change some of the pixel colors and BitBlt it back. In my attempt to make a rectangle of red pixels (or any color) that is 800 pixels in width and 900 in height, I end up with 4 rectangles that are 200 pixels in width and 225 pixels in height, that are separated by 36 pixels and that are alternating is color between red a blue. I'm guessing that this has something to do with the padding. I'd really appreciate an help you can offer!
CDC\* pDC=GetDC(); HDC hDC = \*pDC; HDC hDCMem = CreateCompatibleDC(hDC); BYTE\* lpBitmapBits = NULL; BITMAPINFO bi; ZeroMemory(&bi, sizeof(BITMAPINFO)); bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bi.bmiHeader.biWidth = m\_rcMainRect.Width(); bi.bmiHeader.biHeight = -m\_rcMainRect.Height(); bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; HBITMAP bitmap = ::CreateDIBSection(hDCMem, &bi, DIB\_RGB\_COLORS, (LPVOID\*)&lpBitmapBits, NULL, 0); HGDIOBJ oldbmp = ::SelectObject(hDCMem, bitmap); BitBlt(hDCMem, 0, 0, m\_rcMainRect.Width(), m\_rcMainRect.Height(), hDC, 0, 0, SRCCOPY); for(int x=0; x<800; x=x+4) { for(int y=0; y<900; y++) { lpBitmapBits\[(y\*m\_rcMainRect.Width())+x\] = 0x00; //alpha channel? lpBitmapBits\[(y\*m\_rcMainRect.Width())+x+1\] = 0x00; lpBitmapBits\[(y\*m\_rcMainRect.Width())+x+2\] = 0xFF; lpBitmapBits\[(y\*m\_rcMainRect.Width())+x+3\] = 0x00; } } BitBlt(hDC, 0, 0, m\_rcMainRect.Width(), m\_rcMainRect.Height(), hDCMem, 0, 0, SRCCOPY); SelectObject(hDCMem,oldbmp); DeleteDC(hDCMem); DeleteObject(bitmap);