Webnode

VB - Get RGB from Picturebox

In this tutorial I'll teach you how you can get the RGB code from the mouseposition on a picturebox.

You will need to make a new windows form application , call it GetPixel

Add a picturebox and a button on your form:

Change the picturebox propertie SizeMode to StretchImage:

Click the Picturebox once again and select the yellow events button in the properties windows and double click on the event MouseDown:

Then add the following codes:

 

  1. Private Sub PictureBox1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
  2.         Dim mybmp As New System.Drawing.Bitmap(PictureBox1.Image)
  3.         MessageBox.Show(mybmp.GetPixel(e.X, e.Y).ToString())
  4.     End Sub

Go back to the design of your form and add a OpenFileDialog:

Double click the Load button on your form and add the following codes:

 

  1. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  2.         OpenFileDialog1.ShowDialog()
  3.         PictureBox1.ImageLocation = OpenFileDialog1.FileName
  4.     End Sub

When you load an image and click on your picturebox you should get the RGB code from your mouseposition,

If you have a question, please leave a comment below !


Topic: VB - Get RGB from Picturebox

No comments found.