Hi.I used the following code (in VB.Net 2105) for pikingpicking the color of the pixel at curser point on a picture box which a rectangle has been drawn on that with white color of the boundary and filled by red color.
Private Sub PictureBox1_mosevnt(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
Dim bmp_dumy As Bitmap = New Bitmap(1, 1)
Using gr_new = Graphics.FromImage(bmp_dumy)
gr_new.CopyFromScreen(Me.Cursor.Position, New Point(0, 0), New Size(1, 1))
End Using
Dim pixel As Drawing.Color = bmp_dumy.GetPixel(0, 0)
If pixel.A.ToString = 255 And pixel.R.ToString = 255 And pixel.G.ToString = 255 And pixel.B.ToString = 255 Then
MsgBox("White color pixel is detected" & pixel.ToString(), MessageBoxButtons.OK)
PictureBox1.BackColor = pixel
Label1.Text$ = bmp_dumy.GetPixel(0, 0).ToString
Dim p As New Point
p.X = (Me.Width / 2) - (Label1.Width / 2)
p.Y = Label1.Top
Label1.Location = p
Me.Invalidate()
end if
End sub
Problem:
However when I wanted to put two for--next loops and scan the surface area of picture box (Me.Cursor.PositionMe.Cursor.Position ---> new point(x_pix,y_pix) it dosen'tdoesn't works(the if.
The IF condition isn't reached), as follows :
Private Sub PictureBox1_mosevnt(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
Dim bmp_dumy As Bitmap = New Bitmap(1, 1)
For x_pix As Integer = 0 To Me.Width - 1
For y_pix As Integer = 0 To Me.Height - 1
Using gr_new = Graphics.FromImage(bmp_dumy)
gr_new.CopyFromScreen(new point(x_pix,y_pix), New Point(0, 0), New Size(1, 1))
End Using
Dim pixel As Drawing.Color = bmp_dumy.GetPixel(0, 0)
If pixel.A.ToString = 255 And pixel.R.ToString = 255 And pixel.G.ToString = 255 And pixel.B.ToString = 255 Then
MsgBox("White color pixel is detected" & pixel.ToString(), MessageBoxButtons.OK)
PictureBox1.BackColor = pixel
Label1.Text$ = bmp_dumy.GetPixel(0, 0).ToString
Dim p As New Point
p.X = (Me.Width / 2) - (Label1.Width / 2)
p.Y = Label1.Top
Label1.Location = p
Me.Invalidate()
end if
Next
Next
End sub
would you please help me about this problem.
vb.net ,image-processing, colors, pixel, picturebox
What I have tried:
the two code used with mouseMove and MouseClick events of picturebox has been shown before.