Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to blit a System.Drawing.Image into DirectDraw.Surface ?

How to blit a System.Drawing.Image into DirectDraw.Surface ?

Scheduled Pinned Locked Moved C#
questiongraphicstutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ralfoide
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • R ralfoide

      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

      J Offline
      J Offline
      Jeremy Kimball
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • J 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

        R Offline
        R Offline
        ralfoide
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups