Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GDI drawing onto a 4-bit bitmap

GDI drawing onto a 4-bit bitmap

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpperformancequestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #1

    Greetings folks! I created a DIB section with 4 bits per pixel, so 16 colors. I selected this DIB into a DC and am trying to draw into it using FillSolidRect and Ellipse, but all i get are zeroes in the pixel data. I specified the palette entries when creating the DIB, i also tried creating a CPalette from the DIB's palette and selecting it for the DC before drawing but no matter what i do i get nothing but zeroes. All the drawing code succeeds, so there's no visible indication of failure. What might i be doing wrong here? Here's some stripped down code:

    unsigned char BIHeadMem[sizeof(BITMAPINFO) + 16 * sizeof(RGBQUAD)] = {0};
    BITMAPINFO &BIHead = *(BITMAPINFO *)BIHeadMem;

    BIHead.bmiHeader.biSize = sizeof(BIHead.bmiHeader);
    BIHead.bmiHeader.biBitCount = 4;
    BIHead.bmiHeader.biClrImportant = 0;
    BIHead.bmiHeader.biClrUsed = 0;
    BIHead.bmiHeader.biCompression = BI_RGB;
    BIHead.bmiHeader.biSizeImage = 0;
    BIHead.bmiHeader.biXPelsPerMeter = 0;
    BIHead.bmiHeader.biYPelsPerMeter = 0;
    BIHead.bmiHeader.biWidth = 32;
    BIHead.bmiHeader.biHeight = -32;
    BIHead.bmiHeader.biPlanes = 1;

    for (int I = 0; I < 16; I++)
    {
    BIHead.bmiColors[I].rgbRed = BIHead.bmiColors[I].rgbBlue = BIHead.bmiColors[I].rgbGreen = (BYTE)I;
    BIHead.bmiColors[I].rgbReserved = 0;
    }

    void *DummyPixels;
    CBitmap bmp;
    bmp.Attach(CreateDIBSection(NULL, &BIHead, DIB_RGB_COLORS, &DummyPixels, NULL, 0)); //The creation succeeds...

    CDC memDC;
    memDC.CreateCompatibleDC(NULL); //Creation succeeds...
    memDC.SelectObject(&bmp); //SelectObject succeeds...

    //Here i also tried creating a LOGPALETTE from the DIB's pal, making a CPalette from that and select it for memDC
    //with CDC::SelectPalette (and CDC::RealizePalette) but this seems to make no difference whatsoever

    memDC.FillSolidRect(0, 0, fSizeCache.WellSize, fSizeCache.WellSize, RGB(0, 0, 0)); //Success

    CPen pen;
    CBrush brush(RGB(2, 2, 2));

    pen.CreatePen(PS_SOLID, 1, RGB(1, 1, 1));
    memDC.SelectObject(&brush);
    memDC.SelectObject(&pen);
    memDC.Ellipse(0, 0, 32, 32); //Success...

    When i check the memory pointed at by DummyPixels, it's all zeroes, if i write to this memory "manually" the palette indexes from 0 to 15 i get what i expect when blitting the DIB to antoher DC, so the DIB itself should be ok. I guess the problem here is something completely obvious and i am just not aware of it. Thanks in advance for any help.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups