VB Code:
  1. Public Function Mask(ByVal iPic As Bitmap) As Bitmap
  2.  
  3.         Dim NewMask As Bitmap = New Bitmap(iPic.Width, iPic.Height)
  4.         Dim GDColor As Color
  5.  
  6.         Dim i As New Rectangle
  7.         i.Width = iPic.Width
  8.         i.Height = iPic.Height
  9.  
  10.         Dim BitData As BitmapData = NewMask.LockBits(i, Imaging.ImageLockMode.ReadWrite, iPic.PixelFormat)
  11.         Dim bit2data As BitmapData = iPic.LockBits(i, ImageLockMode.ReadWrite, iPic.PixelFormat)
  12.  
  13.         For y As Integer = 0 To iPic.Height - 1
  14.             For x As Integer = 0 To iPic.Width - 1
  15.                 GDColor = iPic.GetPixel(x, y) ' ERROR HERE
  16.  
  17.                 If GDColor.ToArgb <> Color.Black.ToArgb Then
  18.                     NewMask.SetPixel(x, y, Color.Black)
  19.                 Else
  20.                     NewMask.SetPixel(x, y, Color.White)
  21.                 End If
  22.             Next x
  23.         Next y
  24.  
  25.         NewMask.UnlockBits(BitData)
  26.         iPic.UnlockBits(bit2data)
  27.  
  28.         Return NewMask
  29.     End Function

Am i using lockbits incorrectly? I've done my research it seems ok, but it says that my bitmap is locked on the line above. I have it set to read/write though :/