你所需要的代码如下:
If InCheck.Value = 0 Then
For i = 0 To PicMain.Height
MaskLine = False
For j = 0 To PicMain.Width
CurrentColor = GetPixel(PicMain.hdc, j, i)
If j < PicMain.Width Then
TwoColor = GetPixel(PicMain.hdc, j + 1, i)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Width
OtherColor = GetPixel(PicMain.hdc, k, i)
If k < PicMain.Width Then
OtherTwoColor = GetPixel(PicMain.hdc, k + 1, i)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = False Then
SetPixel PicMain.hdc, j, i, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
For i = 0 To PicMain.Width
MaskLine = False
For j = 0 To PicMain.Height
CurrentColor = GetPixel(PicMain.hdc, i, j)
If j < PicMain.Height Then
TwoColor = GetPixel(PicMain.hdc, i, j + 1)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Height
OtherColor = GetPixel(PicMain.hdc, i, k)
If k < PicMain.Height Then
OtherTwoColor = GetPixel(PicMain.hdc, i, k + 1)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = False Then
SetPixel PicMain.hdc, i, j, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
End If
If InCheck.Value = 1 Then
For i = 0 To PicMain.Height
MaskLine = False
For j = 0 To PicMain.Width
CurrentColor = GetPixel(PicMain.hdc, j, i)
If j < PicMain.Width Then
TwoColor = GetPixel(PicMain.hdc, j + 1, i)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Width
OtherColor = GetPixel(PicMain.hdc, k, i)
If k < PicMain.Width Then
OtherTwoColor = GetPixel(PicMain.hdc, k + 1, i)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = True Then
SetPixel PicMain.hdc, j, i, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
For i = 0 To PicMain.Width
MaskLine = False
For j = 0 To PicMain.Height
CurrentColor = GetPixel(PicMain.hdc, i, j)
If j < PicMain.Height Then
TwoColor = GetPixel(PicMain.hdc, i, j + 1)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Height
OtherColor = GetPixel(PicMain.hdc, i, k)
If k < PicMain.Height Then
OtherTwoColor = GetPixel(PicMain.hdc, i, k + 1)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = True Then
SetPixel PicMain.hdc, i, j, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
End If
' 原创,完整程序见http://3rdapple.51.net/
--------------------------------------------------------------------
这是核心代码,不过还有些BUG,自己修改吧!
--------------------------------------------------------------------
另,想有更快的速度,请使用DIB技术。
--------------------------------------------------------------------
If InCheck.Value = 0 Then
For i = 0 To PicMain.Height
MaskLine = False
For j = 0 To PicMain.Width
CurrentColor = GetPixel(PicMain.hdc, j, i)
If j < PicMain.Width Then
TwoColor = GetPixel(PicMain.hdc, j + 1, i)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Width
OtherColor = GetPixel(PicMain.hdc, k, i)
If k < PicMain.Width Then
OtherTwoColor = GetPixel(PicMain.hdc, k + 1, i)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = False Then
SetPixel PicMain.hdc, j, i, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
For i = 0 To PicMain.Width
MaskLine = False
For j = 0 To PicMain.Height
CurrentColor = GetPixel(PicMain.hdc, i, j)
If j < PicMain.Height Then
TwoColor = GetPixel(PicMain.hdc, i, j + 1)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Height
OtherColor = GetPixel(PicMain.hdc, i, k)
If k < PicMain.Height Then
OtherTwoColor = GetPixel(PicMain.hdc, i, k + 1)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = False Then
SetPixel PicMain.hdc, i, j, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
End If
If InCheck.Value = 1 Then
For i = 0 To PicMain.Height
MaskLine = False
For j = 0 To PicMain.Width
CurrentColor = GetPixel(PicMain.hdc, j, i)
If j < PicMain.Width Then
TwoColor = GetPixel(PicMain.hdc, j + 1, i)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Width
OtherColor = GetPixel(PicMain.hdc, k, i)
If k < PicMain.Width Then
OtherTwoColor = GetPixel(PicMain.hdc, k + 1, i)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = True Then
SetPixel PicMain.hdc, j, i, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
For i = 0 To PicMain.Width
MaskLine = False
For j = 0 To PicMain.Height
CurrentColor = GetPixel(PicMain.hdc, i, j)
If j < PicMain.Height Then
TwoColor = GetPixel(PicMain.hdc, i, j + 1)
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then
MaskLine = True
LineCounts = 0
For k = j + 1 To PicMain.Height
OtherColor = GetPixel(PicMain.hdc, i, k)
If k < PicMain.Height Then
OtherTwoColor = GetPixel(PicMain.hdc, i, k + 1)
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then
LineCounts = LineCounts + 1
End If
Next k
If LineCounts = 0 Then
MaskLine = False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = True Then
SetPixel PicMain.hdc, i, j, RGB(ToA, ToB, ToC)
End If
End If
Next j
Next i
End If
' 原创,完整程序见http://3rdapple.51.net/
--------------------------------------------------------------------
这是核心代码,不过还有些BUG,自己修改吧!
--------------------------------------------------------------------
另,想有更快的速度,请使用DIB技术。
--------------------------------------------------------------------
本程序的上下两部分(以对InCheck.Value量的判断为界),现在我讲解的时候仅说明上面一部分(和下面一部分非常类似)
--------------------------------------------------------------------
这一部分又分为两块,分别是横向扫描和纵向扫描,这样就不会漏掉了,在这里我仅分析横向扫描(和纵向扫描类似)。
--------------------------------------------------------------------
For i = 0 To PicMain.Height
MaskLine = False '初始化MaskLine变量
For j = 0 To PicMain.Width
CurrentColor = GetPixel(PicMain.hdc, j, i) '取得当前所在点的颜色值
If j < PicMain.Width Then
TwoColor = GetPixel(PicMain.hdc, j + 1, i) '取得当前所在点前面一点的值, 用途是当是一条很宽的线条把图象围起来时不会误判
End If
If CurrentColor = RGB(A, B, C) And TwoColor <> CurrentColor Then '当遇到一条线条时
MaskLine = True 'MaskLine变量赋值为True
LineCounts = 0 'LineCounts作用是计算剩余线条的数量
For k = j + 1 To PicMain.Width '开始向后循环, 计算线条的数量
OtherColor = GetPixel(PicMain.hdc, k, i) '取得颜色值
If k < PicMain.Width Then
OtherTwoColor = GetPixel(PicMain.hdc, k + 1, i) '取得前面一点的值, 用途是当是一条很宽的线条把图象围起来时不会误判
End If
If OtherColor = RGB(A, B, C) And OtherTwoColor <> OtherColor Then '如果遇到线条
LineCounts = LineCounts + 1 'LineCounts记数器上加一
End If
Next k
If LineCounts = 0 Then '如果没有遇到线条
MaskLine = False 'MaskLine变量赋值为False
End If
Else
If CurrentColor <> RGB(A, B, C) And MaskLine = False Then '当当当前颜色既不是线条颜色, 而且也不在范围之内时(由MaskLine变量确定)
SetPixel PicMain.hdc, j, i, RGB(ToA, ToB, ToC) '重新设置当前点的颜色值
End If
End If
Next j
Next i
--------------------------------------------------------------------
另,本人写程序没有写注释的习惯,如果给你带来不便,请见谅
--------------------------------------------------------------------
Made by Thirdapple's Studio