Solved

Saving a DDSurface to .bmp file

Posted on 2000-02-24
7
264 Views
Last Modified: 2012-08-14
I curently building a game developping tool that use DirectDraw and VB, it's near completion, the last thing left is the saving feature that will take a DirectDraw surface and save it to the disk.  I search the web, all my books and ask on many message board, but no one has reply me with something I could use.  I really need an answer it's the sixth day I'm on this problem.

Thank you.
0
Comment
Question by:Kayan
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Accepted Solution

by:
pjknibbs earned 75 total points
ID: 2554418
I don't think there's any easy way to do this. The method I once used (albeit in C, not VB) went as follows:

1) Get a device context for the DD surface using GetDC().
2) Create a compatible memory DC using the API function CreateCompatibleDC().
3) Use API function CreateDIBSection() to create a DIB of the appropriate size.
4) Select this DIB into the memory DC created in step 2.
5) Use BitBlt() to copy the DD surface from the DC in (1) to the memory DC.

The DIBSection now contains the DirectDraw surface as a DIB, and you can do what you like with it.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2554465
"HOWTO: Capture and Print the Screen, a Form, or any Window"

http://support.microsoft.com/support/kb/articles/Q161/2/99.ASP
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2554515
Erick37: Are you sure that method will work with a DirectDraw surface...particularly if it has no window associated with it?

Kayan: I should clarify my earlier answer by saying the GetDC() call in step 1 is the GetDC() method of the DirectDrawSurface interface, not the normal Windows GetDC() call.
0
Independent Software Vendors: 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!

 

Author Comment

by:Kayan
ID: 2554844
pjknibbs:Now I searching a way to get it work in vb with a call to gdi32.  And I need a call to CreateFileMaping because the hSection of CreateDIBSection need to be notnull if a want to be able to use the handle to the bitmap.

Erick37:No there is no window associated with it, it's a memory surface.

0
 

Author Comment

by:Kayan
ID: 2554859
pjknibbs:Now I searching a way to get it work in vb with a call to gdi32.  And I need a call to CreateFileMaping because the hSection of CreateDIBSection need to be notnull if a want to be able to use the handle to the bitmap.

Erick37:No there is no window associated with it, it's a memory surface.

0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2554949
Yes, I hadn't thought of that. You can do it without using the DIB section, but it's a bit more complicated. Basically, instead of CreateDIBSection() you use CreateCompatibleBitmap(); after you've done the step 5 blit you have to call GetDIBits() to retrieve the bitmap as a DIB.

I'm not sure what you mean about the call to GDI32, however.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2555259
In the MS article I pointed to, the window handle is only used in getting the DC of the target for subsequent bitblting to a memory DC.  If GetDC() works, then the article may provide some hints as to capturing the image.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

685 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