Click here to Skip to main content
16,022,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB.NET
Private Sub PictureBox1_mosevnt(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove

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

' Next
'Next

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 :
VB.NET
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.
Posted
Updated 28-Sep-24 22:47pm
v3
Comments
0x01AA 29-Sep-24 9:04am    
On a first glance: gr_new.CopyFromScreen does not involve the mouse coordinates

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900