The function below is in a class that contains a member bitmap object, m_bmp. The intent is to return a piece of the bitmap as a smaller bitmap object. This is cribbed and slightly altered from some working code, and I can't figure out how I broke it -- the returned bitmap is just black.
Oh, and I'm not using Clone because Clone may be too smart, and seems to play with the data format... I'm trying dumber alternatives that hopefully won't affect that.
Any ideas? Thanks.
Public Function Copy(ByVal r As Rectangle) As Bitmap
Dim newbmp As New Bitmap(r.Width, r.Height, m_bmp.PixelFormat)
Dim newgraphic As Graphics = Graphics.FromImage(m_bmp)
Dim oldgraphic As Graphics = Graphics.FromImage(newbmp)
Dim newhdc As IntPtr = newgraphic.GetHdc
Dim oldhdc As IntPtr = oldgraphic.GetHdc
Dim i As Integer = BitBlt(newhdc, 0, 0, r.Width, r.Height, oldhdc, r.X, r.Y, SRCCOPY) '<-- i returns 1, meaning success