OBS! 'Pointer(Of xxx) is invalid. You've got to do something like:
Private Sub contrast_function()
Dim nContrast As Double = 30
Dim pixel As Double = 0, contrast As Double = (100.0 + nContrast) / 100.0
contrast *= contrast
Dim red As Integer, green As Integer, blue As Integer
Dim b As New Bitmap( pictureBox1.Image)
Dim bmData As BitmapData = b.LockBits(New Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
Dim stride As Integer = bmData.Stride
Dim Scan0 As System.IntPtr = bmData.Scan0
Dim buffer(stride * bmData.Height - 1) As Byte
Dim p = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0)
p = Scan0
Dim nOffset As Integer = stride - b.Width * 3
Dim offSet = 0
For y As Integer = 0 To b.Height - 1
For x As Integer = 0 To b.Width - 1
blue = buffer(0 + offSet)
green = buffer(1 + offSet)
red = buffer(2 + offSet)
pixel = red / 255.0
pixel -= 0.5
pixel *= contrast
pixel += 0.5
pixel *= 255
If pixel < 0 Then
pixel = 0
End If
If pixel > 255 Then
pixel = 255
End If
buffer(2 + offSet) = CByte(Math.Truncate(pixel))
pixel = green / 255.0
pixel -= 0.5
pixel *= contrast
pixel += 0.5
pixel *= 255
If pixel < 0 Then
pixel = 0
End If
If pixel > 255 Then
pixel = 255
End If
buffer(1 + offSet) = CByte(Math.Truncate(pixel))
pixel = blue / 255.0
pixel -= 0.5
pixel *= contrast
pixel += 0.5
pixel *= 255
If pixel < 0 Then
pixel = 0
End If
If pixel > 255 Then
pixel = 255
End If
buffer(0) = CByte(Math.Truncate(pixel))
offSet += 3
Next
offSet += nOffset
Next
b.UnlockBits(bmData)
pictureBox1.Image = DirectCast(b, Image)
End Sub