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

  • Home
  • SEARCH
  • 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 6790223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:42:00+00:00 2026-05-26T17:42:00+00:00

Problem: can’t get image to the screen… ?? I am looking for a methodology

  • 0

Problem: can’t get image to the screen… ??
I am looking for a methodology that I can work from the camera and a file that I can modify the bitmap using GetDIBits and SetDIBits and write to the screen.

So far from a file to the screen… not working

HDC hdcScreen;
HDC hdcWindow;
HDC hdcMemDC = NULL;
HBITMAP hbmScreen = NULL;
BITMAP bmpScreen;

BITMAPFILEHEADER   bmfHeader;    
BITMAPINFOHEADER   bi;
BITMAPINFO bif;




// Retrieve the handle to a display device context for the client 
// area of the window. 
hdcScreen = ::GetDC(NULL);
// hdcWindow = ::GetDC(hWndC);

// Create a compatible DC which is used in a BitBlt from the window DC
hdcMemDC = CreateCompatibleDC(hdcWindow); 

HANDLE hFile = ::CreateFile("c:\\captureqwsx.bmp",
    GENERIC_READ,
    0,
    NULL,
    OPEN_ALWAYS,
    FILE_ATTRIBUTE_NORMAL, NULL);   


DWORD nBytesRead = 0;
ReadFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &nBytesRead, NULL);
ReadFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &nBytesRead, NULL);
//HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
char *lpbitmap;// = (char *)GlobalLock(hDIB); 
DWORD dwBmpSize;// = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;
ReadFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &nBytesRead, NULL);




//Close the handle for the file that was created
CloseHandle(hFile);



//CRect rect;
//GetClientRect(&rect);

bif.bmiHeader = bi;

HDC hDC = hdcWindow;


HBITMAP hBitmap;
HDC hMemDC;

hBitmap = CreateCompatibleBitmap(hDC, bi.biWidth, bi.biHeight);
hMemDC = CreateCompatibleDC(hDC);
SetDIBits(hDC, hBitmap, 0, bi.biHeight, lpbitmap, &bif, DIB_RGB_COLORS);
SelectObject(hMemDC, hBitmap);
BitBlt(hDC, 0, 0, bi.biWidth, bi.biHeight, hMemDC, 0, 0, SRCCOPY);

DeleteObject(SelectObject(hMemDC, hBitmap));
DeleteDC(hMemDC);
  • 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-05-26T17:42:01+00:00Added an answer on May 26, 2026 at 5:42 pm

    Here you retrieve the DC for the entire screen. Is that what you really want?

    GetDC(NULL);
    

    Perhaps you should remove that and uncomment the following line:

    // hdcWindow = ::GetDC(hWndC); 
    

    According to posted example, you are calling CreateCompatibleDC() with uninitialized ‘hdcWindow’ argument.

    hdcMemDC = CreateCompatibleDC(hdcWindow);
    

    After reading BITMAPFILEHEADER and BITMAPINFOHEADER, you should move file pointer to BITMAPFILEHEADER::bfOffBits offest.
    Then you should call ReadFile() to read the bitmap itself. Btw, required buffer size is in BITMAPINFOHEADER::biSizeImage.

    Since hdcWindow is uninitialized, the hDC remains uninitialized too:

    hDC = hdcWindow;
    

    Did you check the return value of SetDIBits()?

    Try to modify the following line:

    hOldBitmap = SelectObject(hMemDC, hBitmap);
    

    Then, after BitBlt():

    DeleteObject(SelectObject(hMemDC, hOldBitmap));
    

    I don’t know if this is final solution for your problem, but it’s a start.

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

Sidebar

Related Questions

I think that this problem can be sorted using reflection (a technology which I'm
I've created a custom exception for a very specific problem that can go wrong.
I've heard that the 8-puzzle problem can be tackled via BFS, but I don't
My problem can be simplified to a List<> with X and Y coordinates that
I have some problem with PostSharp (I assume that problem can be solved by
I believe that the Hamiltonian cycle problem can be summed up as the following:
From what I've been seeing around the internet, this problem can't really be solved
Problem: Can't get Unicode character to print correctly. Here is my grammar: options {
I solved the N- Queen problem with the condition that there can only be
I'm building a database and have run into a problem that I can't seem

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.