Click here to Skip to main content
16,010,553 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralHelp with I/O Pin
dmt7-Dec-01 5:19
dmt7-Dec-01 5:19 
GeneralRe: Help with I/O Pin
David Chamberlain7-Dec-01 7:38
David Chamberlain7-Dec-01 7:38 
GeneralA data grid Pin
andysolman7-Dec-01 3:09
andysolman7-Dec-01 3:09 
GeneralRe: A data grid Pin
Christian Graus7-Dec-01 10:49
protectorChristian Graus7-Dec-01 10:49 
GeneralSystem wide keyboard hook crashes my (16 bit) app Pin
Jorik7-Dec-01 2:24
Jorik7-Dec-01 2:24 
GeneralLoad font resource... Pin
BlackSmith7-Dec-01 0:44
BlackSmith7-Dec-01 0:44 
GeneralRe: Load font resource... Pin
Rickard Andersson207-Dec-01 3:16
Rickard Andersson207-Dec-01 3:16 
GeneralModifing DIB colour table Pin
PJ Arends6-Dec-01 23:24
professionalPJ Arends6-Dec-01 23:24 
Ok, I give up. I am going to have to give in and ask for some help.
I am trying to change the colours of a bitmap (make it grayscale). I have got it working for 16, 24, and 32 bit bitmaps, but I am lost as to how to do this for 4 and 8 bit bitmapsConfused | :confused:

The HBITMAP passed into my function could be a DIB or a DDB
HBITMAP #####::GrayScale(CDC *pDC, HBITMAP hBitmap)
{
    BITMAP bmp;
    ::GetObject(hBitmap, sizeof(BITMAP), &bmp);

    if (bmp.bmBitsPixel < 16)
    {

    // Can not get this to work ??????

    }
    else
    {
        HBITMAP hDib = (HBITMAP)::CopyImage(hBitmap, IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG | LR_CREATEDIBSECTION);
        DIBSECTION DibSection;
        ::GetObject(hDib, sizeof(DIBSECTION), &DibSection);
        
        int Size = DibSection.dsBmih.biWidth * DibSection.dsBmih.biHeight;
        
        BITMAPINFO bmi;
        bmi.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
        bmi.bmiHeader.biHeight        = bm.bmHeight;
        bmi.bmiHeader.biWidth         = bm.bmWidth;
        bmi.bmiHeader.biPlanes        = 1;
        bmi.bmiHeader.biBitCount      = bm.bmBitsPixel;
        bmi.bmiHeader.biCompression   = BI_RGB;
        bmi.bmiHeader.biSizeImage     = ((bm.bmWidth * bm.bmBitsPixel + 31) & (~31)) / 8 * bm.bmHeight;
        bmi.bmiHeader.biXPelsPerMeter = 0;
        bmi.bmiHeader.biYPelsPerMeter = 0;
        bmi.bmiHeader.biClrUsed       = 0;
        bmi.bmiHeader.biClrImportant  = 0;
        
        BYTE *pBits;
        ::GetDIBits(pDC->m_hDC, hDib, 0, bm.bmHeight, pBits, &bmi, DIB_RGB_COLORS);

        ...
        // modify the pBits bitmap bits directly
        // works perfectly
        ...

        ::SetDIBits(pDC->m_hDC, hDib, 0, bm.bmHeight, pBits, &bmi, DIB_RGB_COLORS);
        return hDib;
    }
}

It is my understanding that in 4 and 8 bit bitmaps, the bits returned by GetDIBits() are actually pointers into a colour table, and to change the image to grayscale I have to change the colour table. How do I get access to the colour tableConfused | :confused:
I have tried
::GetDIBColorTable(memDC.m_hDC, 0, 1<<bmp.bmBitsPixel, rgbquad);
For a 256 colour bitmap, ::GetDIBColorTable() returns 256, but the rgbquad array is full of garbage (every entry is 0xcc in debug mode). I have read Zafir Anjum's Drawing an image in grayscale but I could not get that to work the way i wanted either. I have tried several other things but nothing seems to workFrown | :(
I am probably missing something obvious and I hope some one can point out to me what it is.


---
It may be that your sole purpose in life is simply to serve as a warning to others.
GeneralRe: Modifing DIB colour table Pin
Henry Jacobs7-Dec-01 6:32
Henry Jacobs7-Dec-01 6:32 
QuestionCheck e-mail? Pin
Rickard Andersson206-Dec-01 21:52
Rickard Andersson206-Dec-01 21:52 
AnswerRe: Check e-mail? Pin
Michael P Butler6-Dec-01 22:26
Michael P Butler6-Dec-01 22:26 
GeneralRe: Check e-mail? Pin
Mustafa Demirhan6-Dec-01 22:32
Mustafa Demirhan6-Dec-01 22:32 
AnswerRe: Check e-mail? Pin
Nish Nishant6-Dec-01 22:30
sitebuilderNish Nishant6-Dec-01 22:30 
GeneralThis CDC* is killing me Pin
6-Dec-01 21:42
suss6-Dec-01 21:42 
GeneralRe: This CDC* is killing me Pin
Rickard Andersson206-Dec-01 21:56
Rickard Andersson206-Dec-01 21:56 
Questionhow to get the handle of the control of another app Pin
6-Dec-01 20:16
suss6-Dec-01 20:16 
AnswerRe: how to get the handle of the control of another app Pin
Rickard Andersson206-Dec-01 21:42
Rickard Andersson206-Dec-01 21:42 
AnswerRe: how to get the handle of the control of another app Pin
6-Dec-01 22:04
suss6-Dec-01 22:04 
GeneralCTreeCtrl right mouse click handling :( Pin
6-Dec-01 19:44
suss6-Dec-01 19:44 
GeneralRe: CTreeCtrl right mouse click handling :( Pin
6-Dec-01 22:09
suss6-Dec-01 22:09 
GeneralRe: CTreeCtrl right mouse click handling :( Pin
6-Dec-01 22:12
suss6-Dec-01 22:12 
GeneralRe: CTreeCtrl right mouse click handling :( Pin
Morozov Alexey6-Dec-01 23:28
Morozov Alexey6-Dec-01 23:28 
GeneralRe: CTreeCtrl right mouse click handling :( Pin
7-Dec-01 2:57
suss7-Dec-01 2:57 
GeneralRe: CTreeCtrl right mouse click handling :( Pin
7-Dec-01 3:21
suss7-Dec-01 3:21 
GeneralRe: Resources in a static library Pin
Henry Jacobs7-Dec-01 4:15
Henry Jacobs7-Dec-01 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.