Solved

Drawing to a bitmap.

Posted on 2002-05-10
5
453 Views
Last Modified: 2013-11-20
Hi everybody.

 I would like to know how to create a Bitmap which contains the entire view and all the objects displayed n it.

 Note that I'm not asking for a screen capture: the whole idea is drawing the scene n a bitmap instead of n the
screen (as OnDraw does), perhaps creating previously a device context.


I already know how to save a bitmap to a file so do no mess with this point. Please make your answers as explicit
as possible. Code would help.

Hope you know what I mean.


Thanks.
0
Comment
Question by:Iraklis
[X]
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
  • 2
5 Comments
 

Author Comment

by:Iraklis
ID: 7003156
Is this question so difficult. Here you are more points.
0
 
LVL 12

Expert Comment

by:migel
ID: 7003196
Hi!
it isn`t so difficult
in general you have to make several steps:
1. create memory device context
2. bitmap
3. Select bitmap into the memory DC
4. draw your view using this memory DC
5. deselect bitmap
6. You have bitmap and you can save it to the disk

code example:
CMyView::DrawViewInBitmap()
{
CDC dcMem;
CClientDC dcClient(this);
dcMem.CreateCompatibleDC(&dcClient);
CRect rc;
GetClinetRect(rc);
CBitmap bmView;
bmView.CreateCompatibleBitmap(&dcMem, rc.Width(), rc.Height());
CBitmap* pbmOld = dcMem.SelectObject(&bmView);
OnDraw(&dcMem); // draw in this context
dcMem.SelectObject(pbmOld);
// now you have bitmap
StoreBitmap(&bmView);// save it to disk
}
0
 

Author Comment

by:Iraklis
ID: 7004706
Hi, Miguel.

I forgot to mention (my apologies for this) that I'm using a CSCrollView of wich map mode is set to MM_LOMETRIC. Therefore some functions such OnPrepareDC, LPtoDP and SetMapMode must be added.

On the other hand I doubt about the first parameter in
"CreateCompatibleBitmap". Should it be dcClient instead?

I can add more points if required.

Thanks.
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7005058
I don't understand you clearly.Are you want to convert a window which maybe have subwindow to a bitmap? If so, see this:

HBITMAP hBitMap = 0;
BOOL GetWndBmp()
{
   if(hBitMap)
      DeleteObject(hBitMap);

   HDC hCatchDC = CreateCompatibleDC(NULL);
   HDC hTempDC = ::GetDC(NULL);
   RECT rect;
   ::GetWindowRect(m_hWnd/*your window handle*/, &rect);
   int nWidth = rect.right - rect.left;
   int nHeight = rect.bottom - rect.top;
   hBitMap = CreateCompatibleBitmap(hTempDC, nWidth, nHeight);
   HBITMAP oldbmp = (HBITMAP)SelectObject(hCatchDC, hBitMap);
   // let the window draw itself on my hCatchDC
   SendMessage(WM_PRINT, (WPARAM)hCatchDC, PRF_CHILDREN | PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED);

   ::ReleaseDC(NULL, hTempDC);

   SelectObject(hCatchDC, oldbmp);
   DeleteDC(hCatchDC);
   return TRUE;
}

0
 
LVL 12

Accepted Solution

by:
migel earned 251 total points
ID: 7005361
oops
of course you must use clientDC
bmView.CreateCompatibleBitmap(&dcClient, rc.Width(), rc.Height());
and add
     OnPrepareDC(&dcMem);
before OnDraw(&dcMem);
in general all preparation for drawing such as: SetMapMode, SetViewportExt and so on, you must do in the OnPrepareDC so no other preparation in my function need.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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