Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9295901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:43:02+00:00 2026-06-18T21:43:02+00:00

When I set up and create a 24-bit bitmap like this: //fileheader BITMAPFILEHEADER* bf

  • 0

When I set up and create a 24-bit bitmap like this:

   //fileheader
    BITMAPFILEHEADER* bf = new BITMAPFILEHEADER;
    bf->bfType = 0x4d42;
    bf->bfSize = 6054400 + 54;
    bf->bfOffBits = 54;

    //infoheader
    BITMAPINFOHEADER* bi = new BITMAPINFOHEADER;
    bi->biSize = 40;
    bi->biWidth = 2752;
    bi->biHeight = -733;
    bi->biPlanes = 1;
    bi->biBitCount = 24;
    bi->biCompression = 0;
    //bi->biSizeImage = 6054400;
    bi->biXPelsPerMeter = 2835;
    bi->biYPelsPerMeter = 2835;
    bi->biClrUsed = 0;
    bi->biClrImportant = 0;

    pFrame->GetImage(m_imageData);

    //
    //create bitmap...
    //(hbit is a global variable)

    BITMAPINFO* bmi;
    bmi = (BITMAPINFO*)bi; 
    HDC hdc = ::GetDC(NULL);

    hbit = CreateDIBitmap(hdc, bi, CBM_INIT, m_imageData, bmi, DIB_RGB_COLORS);

I get an output image like this:
image1

But when I change bitcount from 24 to 8 (which also allows for 3x image size, allowing me to go from 733 width to the image’s natural width of 2200), I get an image like this (along with a lot of instability):

image2

My output looks like this:

    BITMAP* bi = new BITMAP;
    CBitmap bmp;
    bmp.Attach(hbit);
    CClientDC dc(pWnd);
    CDC bmDC;
    bmDC.CreateCompatibleDC(&dc);
    CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
    bmp.GetBitmap(bi);
    dc.BitBlt(384,26,bi->bmWidth/3,bi->bmHeight,&bmDC,0,0,SRCCOPY);
    //note: if bitcount is 8, height and width need to be /3, 
          //if 24, only width gets /3 
    bmDC.SelectObject(pOldbmp);

    //explicitly delete everything just to be safe
    delete bi;
    DeleteObject(bmp);
    DeleteObject(dc);
    DeleteObject(pOldbmp);
    DeleteObject(bmDC);

So my questions are:

  • Why is this happening when I switch from 24 to 8?
  • Is there an easy way to output the image as monochrome rather than color?

One last thing:

My coworker wrote this function a long time ago for a similar issue, but he said I may be able to use it. I can’t get it to work, unfortunately:

void CopyMono8ToBgrx(byte* pDestBlue, byte* pDestGreen, byte *pDestRed, byte* pDestAlpha)
    {
        byte*               pSrc;
        byte*               pSrcEnd;

        pSrc = ( byte* ) m_imageData;
        pSrcEnd = pSrc + ( 2752*2200 );

        while ( pSrc < pSrcEnd )
        {
            byte data = *pSrc;

            *pDestBlue  = data;
            *pDestGreen = data;
            *pDestRed   = data;
            *pDestAlpha = 255;  // alpha is always 255 (fully opaque)

            pSrc++;
            pDestBlue   += 4;
            pDestGreen  += 4;
            pDestRed    += 4;
            pDestAlpha  += 4;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:43:03+00:00Added an answer on June 18, 2026 at 9:43 pm

    8 bit per pixel images are assuming a color palette following BITMAPINFOHEADER structure (see BITMAPINFO::bmiColors). If you make the palette to be 256 gray shades, the image is going to me 8 bpp grayscale. Now it’s color with random colors on it.

    The function CopyMono8ToBgrx you quoted creates full color bitmap, with gray individual pixels (R=G=B).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create set of strings and below is the only limitation.
We create a Set as: Set myset = new HashSet() How do we create
I have this code: CREATE TABLE #CategoriesTable ( CategoryId INT, HasAssessment BIT, IsScorm BIT,
I'm a bit of newbie at this and am trying to create a scatter
We have this data set: CREATE TABLE #Changes ( [GUID] varchar(250), Value numeric(36,6), DocumentNumber
I'm trying to create a bit vector set from a given array. Not sure
Is this possible, create a .Net 3.5 Dll(A.dll), reference to Oracle 11g 32 bit
I'm trying to create a Set that contains instances of 'Vertex3<T>'. I'm having a
I am attempting to create a set of folders that comes in from a
I'm trying to create a set of checkboxes that I can check and send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.