Results 1 to 6 of 6

Thread: Getpixel is not working in vb.net

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2008
    Posts
    33

    Getpixel is not working in vb.net

    Look at this code, it's so simple, yet I can't manage to get it to work!! PLEASE HELP ME, I'VE BEEN TRYING TO GET IT TO WORK FOR HOURS!!!!

    on the top of form1 is
    Code:
    Option Strict On
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.Windows.Forms
    Code:
            
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    
    Dim TempBmp As Bitmap = New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)
            Dim MyColor As Color
            TempBmp = System.Drawing.Bitmap.FromHbitmap(PictureBox1.Handle)
            MyColor = (TempBmp.GetPixel(1, 1))
            Label4.Text = MyColor.ToString
    end sub
    And the error happens at this line
    Code:
    Dim TempBmp As Bitmap = New Bitmap(PictureBox1.Image.Size.Width, PictureBox1.Image.Size.Height)
    The error message that I get is
    Code:
    NullReferenceException was unhandled
    Object reference not set to an instance of an object.
    That's everything and there is a picture loaded (partial screenshot of desktop) yet it does not work. How could this be?
    Last edited by replaced; Nov 28th, 2010 at 04:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width