VB. NET octopus program to obtain the RGB value of any image point

Source: Internet
Author: User
Tags getcolor

VB. NET octopus program to obtain the RGB value of any image point
Abstract: Use the GetPixel (x, y) function in the Bitmap class to obtain the specified vertex color, and then obtain the values of R, G, and B respectively.

Create an empty form application, add a Picturebox control, a Button control, three label labels, and three Textbox controls to form Form1.

The following code is very simple. First, select an image and display it on the PictureBox control.

Private Sub btn_ImportPicture_Click (ByVal sender As System. object, ByVal e As System. eventArgs) Handles btn_ImportPicture.Click Dim OpenDialog1 As New OpenFileDialog OpenDialog1.Filter = "JPG format | *. jpg | JPEG format | *. jpeg | PNG format | *. png | ICO file and Gif file | *. ICO; * gif | all files *. * | *. * "If OpenDialog1.ShowDialog = DialogResult. OK Then Dim Path As String = OpenDialog1.FileName PictureBox1.Image = Image. fromFile (Path) End If End Sub
This is the core part. Very simple. Note that to use the GetPixel () function, you must first convert the image to the BitMap format.
  Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown        Dim GetColor As Color = CType(PictureBox1.Image, Bitmap).GetPixel(e.X, e.Y)        txt_B.Text = GetColor.B.ToString        txt_G.Text = GetColor.G.ToString        txt_R.Text = GetColor.R.ToString    End Sub
Yes. If you click a point on the image, the RGB value is displayed below.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.