From MSDN LockBits about the rect
parameter:
Type: System.Drawing.Rectangle
A Rectangle structure that specifies the portion of the Bitmap to lock.
So the Rectangle
you passed in should be in your Bitmap Rectangle which always has Location
as Point.Empty
and the Size
as the size of the bitmap. So the exception is thrown correctly.