我一直试图在图像上用矩形网格化每个字母(在该图像上只有白色和黑色的颜色)。我是这样开始的:
Dim bmp As Bitmap = Label1.Image
Dim xmax As Integer
Dim ymax As Integer
xmax = Label1.Width - 1
ymax = Label1.Height - 1
Dim top, bottom, left, right As Integer
Dim first As Boolean = True
Dim last As Boolean = False
Dim first2 As Boolean = True
Dim last2 As Boolean = False
Dim pen As Pen = Pens.Red
For x = 0 To xmax
For y = 0 To ymax
With bmp.GetPixel(x, y)
If .R = 0 And .G = 0 And .B = 0 And first = True Then
left = x
first = False
last = True
ElseIf .R = 0 And .G = 0 And .B = 0 And last = True Then
right = x
End If
End With
Next y
Next x
For y = 0 To ymax
For x = 0 To xmax
With bmp.GetPixel(x, y)
If .R = 0 And .G = 0 And .B = 0 And first2 = True Then
top = y
first2 = False
last2 = True
ElseIf .R = 0 And .G = 0 And .B = 0 And last2 = True Then
bottom = y
End If
End With
Next x
Next y
first = True
first2 = True
last = False
last2 = False
Dim rect As New Rectangle(left, top, right - left, bottom - top)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawRectangle(pen, rect)
Label1.Image = bmp
它会检查图像上的所有像素,它会得到黑色的像素,我只能在一个字母周围绘制矩形,但我当时不能超过一个。 仍然不能将它用于单独的字母。
我会感谢您的所有回复。