Blitting a bitmap to itself

I have a MemoryDC attached to a Bitmap, and I want to draw the current
contents of the MemoryDC to itself with an offset (thus, the bitmap is
partially drawn over itself; this is used to simulate screen
scrolling). I tried this:

        dc.DrawBitmap(self.mapBitmap, xOffset, yOffset)

(self.mapBitmap is the Bitmap that the DC is attached to)

And while it worked on my OSX machine, it didn't work for another
developer who was running Windows 7. So I replaced the code with this:

        tempDC = wx.MemoryDC()
        tempBitmap = wx.EmptyBitmap(imageWidth, imageHeight)
        tempDC.SelectObject(tempBitmap)
        tempDC.Blit(xOffset, yOffset,
                self.mapBitmap.GetWidth(), self.mapBitmap.GetHeight(),
                dc, 0, 0)
        dc.Blit(0, 0,
                self.mapBitmap.GetWidth(), self.mapBitmap.GetHeight(),
                tempDC, 0, 0)

This works, but I can't help but wonder if there's a better way to
accomplish the same goal. Any suggestions?

-Chris

On Windows you can not have more than one HDC using the same HBITMAP at the same time, so I don't think there is a better way.

···

On 10/11/12 6:45 PM, Chris Weisiger wrote:

I have a MemoryDC attached to a Bitmap, and I want to draw the current
contents of the MemoryDC to itself with an offset (thus, the bitmap is
partially drawn over itself; this is used to simulate screen
scrolling). I tried this:

         dc.DrawBitmap(self.mapBitmap, xOffset, yOffset)

(self.mapBitmap is the Bitmap that the DC is attached to)

And while it worked on my OSX machine, it didn't work for another
developer who was running Windows 7. So I replaced the code with this:

         tempDC = wx.MemoryDC()
         tempBitmap = wx.EmptyBitmap(imageWidth, imageHeight)
         tempDC.SelectObject(tempBitmap)
         tempDC.Blit(xOffset, yOffset,
                 self.mapBitmap.GetWidth(), self.mapBitmap.GetHeight(),
                 dc, 0, 0)
         dc.Blit(0, 0,
                 self.mapBitmap.GetWidth(), self.mapBitmap.GetHeight(),
                 tempDC, 0, 0)

This works, but I can't help but wonder if there's a better way to
accomplish the same goal. Any suggestions?

--
Robin Dunn
Software Craftsman