Solved

Saving a DDSurface to .bmp file

Posted on 2000-02-24
7
258 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Kayan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now