How to blit a System.Drawing.Image into DirectDraw.Surface ?
-
Hi! Naive question 101: what is the easier method (not necesarily the most performant) to blit a System.Drawing.Image into a DirectDraw.Surface? Thanks in advance, -- Ralf
Wouldn't something like this work? (assuming surface is 'mySurface' and Image is 'myImage') System.IntPtr pDC = mySurface.GetDC(); Graphics g = Graphics.FromHdc( pDC ); g.DrawImage( myImage, ..... ); g.ReleaseHdc( pDC ); The key is to remember to release the Device Context, or else you'll leak resources. Let me know if this works (not in front of Studio at the moment) Jeremy Kimball
-
Wouldn't something like this work? (assuming surface is 'mySurface' and Image is 'myImage') System.IntPtr pDC = mySurface.GetDC(); Graphics g = Graphics.FromHdc( pDC ); g.DrawImage( myImage, ..... ); g.ReleaseHdc( pDC ); The key is to remember to release the Device Context, or else you'll leak resources. Let me know if this works (not in front of Studio at the moment) Jeremy Kimball
Thanks, I'm going to try this approach too. In the meantime, I found out that a DirectDraw.Surface can be created directly out of a Bitmap: SurfaceDescription desc = new SurfaceDescription(); desc.SurfaceCaps.OffScreenPlain = true; desc.Width = width; desc.Height = height; Surface surf = new Surface(bitmap, desc, localDevice); It's then easy to use Surface.Draw to blit the surface into another. Your method would let me reuse the same surface always though, so it seems better. Regards -- Ralf