我已经使用createGraphics在pictureBox中创建了一些图形,这些图形是非常简单的块,既可以是一种颜色,也可以是空白。接下来,我想通过鼠标单击来读取检测光标位置是否为彩色的。
我以为这很简单,但是什么也做不了。有一些使用位图和GetPixel进行此操作的示例,但不适用于绘制的图形。
我的代码用于编辑使用微控制器打印到小型LCD屏幕上并存储在字体文件中的字体。这是一些不起作用的代码,该代码获取了字符像素的块,但是我还需要知道单击的区域是白色还是红色。
Private Sub VP_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pictureBox0.MouseClick
Dim grid As Integer = 10
Dim LocX As Integer = e.X
Dim locY As Integer = e.Y
TextBoxX.Text = e.X
TextBoxY.Text = e.Y
TextBoxX.ForeColor = Color.IndianRed
TextBoxY.ForeColor = Color.IndianRed
Dim lX As Integer = e.X \ grid
Dim lY As Integer = e.Y \ grid
Dim uX As Integer = lX + 1
Dim uY As Integer = lY + 1
TextBox21.Text = "(" & lX & "," & lY & ") (" & uX & "," & uY & ")"
Dim c As Color
Dim bmp As Bitmap = pictureBox0.Image.Clone
c = bmp.GetPixel(e.X, e.Y)
TextBox22.Text = c.ToString
End Sub