1.9.10

Picture Get Pixel with VB.NET 2010

Hi Everybody,
I would like to discuss one of the most FAQs regarding how we can see image's RGB values with VB.NET 2010 Windows application ? If you have any questions, please feel free to contact me y_turkeli@yahoo.com or yenerturkeli@v-basic.net.

What is RGB?
RGB(Red,Green,Blue) is a color model which provide in various ways to produce colors.

What is Pixel?
Pixel is a single point of image, in other words, the smallest addressable screen element in a image.

1-) We are creating a new Windows Application Project (picture_get_pixels)



2-) We are designing this windows form in a similar way to bellowing picture
(1 Picturebox, 2 textbox , 2 button)



3-) We are writing this code

Private Sub upld_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upld_btn.Click
Dim open_file As New OpenFileDialog
open_file.Filter = "Pictures Files| *.bmp;*.jpg;*.gif;*.wmf;*.tif;*.png"

Try
If open_file.ShowDialog() = DialogResult.OK Then

picture_bx.Image = Image.FromFile(open_file.FileName)

Else
MsgBox("Please select a picture", vbInformation, "Pictures Files")

End If
Catch ex As Exception
MsgBox(ex.Message, vbCritical, "Pictures Files")
End Try




End Sub

Private Sub get_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles get_btn.Click
Try
Dim r_color As Color
Dim picture_b As New Bitmap(picture_bx.Image)

r_color = picture_b.GetPixel(x_txt.Text, y_txt.Text)

MsgBox("Red Value: " & r_color.R & " Green Value: " & r_color.G & " Blue Value " & r_color.B, vbInformation, "Pictures Files")

Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

4-) Lets start application

5 comments:

  1. sir, i have sintaks like this, but it error to read the RGB. can you help me?

    Private Sub PictureBox2_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
    TextBox1.Text = e.X
    TextBox2.Text = e.Y
    End Sub

    Private Sub PictureBox2_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
    Dim warna As Color
    ListBox1.Items.Clear()
    Dim gambar2 as New Bitmap(PictureBox2.Image)
    warna = gambar2.GetPixel(e.X, e.Y)
    ListBox1.Items.Add(warna.R & " " & warna.G & " " & warna.B)
    end sub

    ReplyDelete
  2. how about black and white colour

    ReplyDelete