Solved

Saving a DDSurface to .bmp file

Posted on 2000-02-24
7
263 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

860 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