An unhandled exception of type 'System.NullReferenceException' occurred in

Additional information: Object reference not set to an instance of an

I am getting this error with this code. The line it highlights is the one
with the arrow. Anyone know what the problem is? Thanks

Dim diag As New OpenFileDialog()

Dim file As String

Dim h, v As Integer

Dim cor As Color

Dim ran As Random

'prompt for image


file = diag.FileName

'create a new bitmap class with the image selected

Dim bi As New Bitmap(file)

PictureBox1.Image = bi

'randomly set pixels to random colors

For h = 0 To bi.Width

For v = 0 To bi.Height

---->bi.SetPixel(h, v, cor.FromArgb(ran.Next(0, 255), ran.Next(0, 255),
ran.Next(0, 255)))



'set the image to the new bitmap

PictureBox1.Image = bi