-
weird error with SetPixels
An unhandled exception of type 'System.NullReferenceException' occurred in
WindowsApplication1.exe
Additional information: Object reference not set to an instance of an
object.
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
diag.ShowDialog()
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)))
Next
Next
'set the image to the new bitmap
PictureBox1.Image = bi
-
Re: weird error with SetPixels
G'day.
This post should have been over in .Technical,
but I will answer it here - no doubt Phil will shift it all over....
You just need to instantiate your "ran" variable; ie change
Dim ran As Random
to Dim ran As Random = New Random()
Cheers,
Paul
-
Re: weird error with SetPixels
ah thank you very much
"Paul Mc" <paulmc@nospam.thehub.com.au> wrote in message
news:3c991d27$1@10.1.10.29...
>
> G'day.
>
> This post should have been over in .Technical,
> but I will answer it here - no doubt Phil will shift it all over....
>
> You just need to instantiate your "ran" variable; ie change
>
> Dim ran As Random
>
> to Dim ran As Random = New Random()
>
> Cheers,
> Paul
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks