|
-
October 17th, 2005, 08:54 PM
#2
Re: How to copy HBITMAP to IDirectDrawSurface
The easiest way is probably to call IDirectDrawSurface::GetDC(), which will get you a GDI-compatible device context for the surface. Then you can use that device context with a GDI function such as BitBlt(), to draw the bitmap on that surface.
Of course, you can't copy the bitmap with just its handle; I'm assuming that you have the bitmap in a memory device context. If you know how to work with bitmaps in pure GDI then you already know how to do this. If not, the basic steps are something like this:
- Get a handle to your bitmap (an HBITMAP) by calling a function like LoadImage().
- Create a compatible memory DC by calling CreateCompatibleDC().
- Select the bitmap into that DC using SelectObject().
- Get a DC for your DirectDraw surface using IDirectDrawSurface::GetDC().
- (Optional) If you need to know the dimensions of the bitmap (or anything else), you can call GetObject().
- Copy the image from one DC to the other using BitBlt().
- Get rid of the memory DC with DeleteDC().
- Release the DirectDraw surface DC using IDirectDrawSurface::ReleaseDC().
Last edited by Smasher/Devourer; October 17th, 2005 at 08:58 PM.
Reason: forgot cleanup steps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|