weird error with SetPixels


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: weird error with SetPixels

  1. #1
    binary digit Guest

    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






  2. #2
    Paul Mc Guest

    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

  3. #3
    binary digit Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center