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 8683669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:06:33+00:00 2026-06-12T22:06:33+00:00

I have got a trouble using the StretchDIBits function. I want to draw a

  • 0

I have got a trouble using the StretchDIBits function.
I want to draw a bitmap made from a buffer. However, the colors I define in the buffer are different from the result on screen.
I have read the documentation and I played with the biCompression (BI_RGB and BI_BITFIELDS) and biClrUsed (0 / 3) parameters of the BITMAPINFOHEADER. I can see some differences depending on their values, but the result is still different from what I am expecting.

Here is the code I am using (it can be inserted in the OnDraw method of a template SDI project to demonstrate the problem).

void CTestStretchDIBitsView::OnDraw(CDC* /*pDC*/)
{
    ...

    CClientDC dc(this);
    CRect rect;
    GetClientRect(&rect);

    DWORD* pBuffer = new DWORD[500 * 500];
    memset(pBuffer, RGB(255, 255, 0), 500 * 500 * sizeof(DWORD));

    LPBITMAPINFO pBmpInfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];

    pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pBmpInfo->bmiHeader.biWidth = 500;
    pBmpInfo->bmiHeader.biHeight = 500;
    pBmpInfo->bmiHeader.biPlanes = 1;
    pBmpInfo->bmiHeader.biBitCount = 32;
    pBmpInfo->bmiHeader.biCompression = BI_BITFIELDS;
    pBmpInfo->bmiHeader.biSizeImage = 500 * 500;
    pBmpInfo->bmiHeader.biXPelsPerMeter = 0;
    pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
    pBmpInfo->bmiHeader.biClrUsed = 0;
    pBmpInfo->bmiHeader.biClrImportant = 0;

    SetStretchBltMode(dc.m_hDC, STRETCH_DELETESCANS);
    StretchDIBits(dc.m_hDC, 
                    0, 
                    rect.Height(), 
                    rect.Width(), 
                    -rect.Height(), 
                    0, 
                    0, 
                    500, 
                    500, 
                    pBuffer, 
                    pBmpInfo, 
                    DIB_RGB_COLORS, 
                    SRCCOPY);

    delete[] pBmpInfo;
    delete[] pBuffer;
}
  • 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-12T22:06:36+00:00Added an answer on June 12, 2026 at 10:06 pm

    The problem didn’t come from the StretchDIBits function but from the initialization of the buffer used as the bitmap here.
    memset(…) function was misused.
    With an initialization such as :

    int Color = RGB(255, 0, 0);
    
    for (int i = 0 ; i < 500 * 500 ; i++)
        pBuffer[i] = Color;
    

    I get a perfectly blue image as expected.

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

Sidebar

Related Questions

i'v got a trouble, i want to use Ckeditor with my project, i have
I have got a big trouble in my Xml generator using C#. I could
Why have I got trouble with charset on echo? $url = http://ru.wikipedia.org; $site=file_get_contents($url); echo
I got trouble on Member Description show up. For example, I have two laptops.
I have a trouble deploying an ear in jboss under eclipse. I got a
Have got an NSString *str = @12345.6789 and want to find out if there
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I'm having trouble using I18n.translate to translate an array. Specifically, I've got this array,
i've got the trouble when developing iPhone apps. i want to make my own
I have a Rails 3 app and I'm using Devise and jQTouch. I've got

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.