How save Screen to Bitmap image?

Posted on 2000-03-23
Last Modified: 2010-05-18
How save Screen to Bitmap image in C++?
Please can anyone send me example code?
Question by:Viesturs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 22

Expert Comment

ID: 2649340
Standard C++ provides no mechanism for this.  Standard C++ doesn't even assume there is a screen, much less contain any features for dealing with bitmaps.

In order to do this you will have t make use of Operating System-specific code.  That raises the question--What operating system do you need this for?

In windows you can use

HDC MemDC = CreateCompatibleDC(ScreenDC);
HBITMAP BitMap = CreateCompatibleBitmap(ScreenDC,GetSystemMetrics(SM_CXSCREEN),GetsystemMetrics(SM_CYSCREEN))
HBITMAP OldBmp = SelectObject(MemDC,BitMap);



The code creates a DC for the screen and a compatible one for a memory bitmap.  Then it creates a memory bitmap the same size as the screen.  It selects the memory bitmap into the memory DC.  Then it copies the screen's bitmap to the memory bitmap with BitBlt().   Then it cleans up by restoring the memory DC's original bitmap (important step!).  and deletes the two DCs.
LVL 14

Expert Comment

ID: 2649359
 WINCAP Captures Screens Using DIB API

Create dib and save to disk.
LVL 14

Accepted Solution

AlexVirochovsky earned 50 total points
ID: 2657118
I repete my reply:
  WINCAP Captures Screens Using DIB API 
Create dib and save to disk.


Author Comment

ID: 2660114
Spasibo. Primer skachal, tolko ne uspel posmotrets. :)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 82
returning a dereferenced pts in C++ 10 171
c++ getting the first 10 characters of a char* string 11 110
How can i compile this github project?? 2 101
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question