|
cumulonimbus 发表于 2012-10-8 13:13
大侠,我这个图片就是黑白图片呀,要怎么弄?给个例子
我这个在窗体上按了鼠标,就成这样了,而且每一 ...
这是文件中的一段 VBA 代码,楼主可以自己去分析吧:
Private Sub UserForm_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
Dim lColor As Long
Dim i As Long, j As Long, idx As Long
Dim m As Long, n As Long, f As Long
Dim ptMargin() As POINTAPI, ptIdx As Long
'Óñ³¾°Ë¢Ìî³ä¸ÃÇøÓò
ExtFloodFill m_hMemDC, x, y, GetPixel(m_hMemDC, x, y), FLOODFILLSURFACE
'»ñµÃÌî³äºóµÄÇøÓòÖÖ×ÓÑÕÉ«
lColor = GetPixel(m_hMemDC, x, y)
'±éÀúÄÚ´æλͼ²éѯÌî³äÇøÓòµÄ±ß½ç
ptIdx = -1
m = IIf(x - 150 < 0, 0, x - 150)
n = IIf(y - 120 < 0, 0, y - 120)
For j = n To y + 120
f = 0
For i = m To x + 150
If GetPixel(m_hMemDC, i, j) = lColor Then
If f = 0 Then 'ÕÒµ½×î×óµÄ±ß½çµã
f = 1
ptIdx = ptIdx + 1
ReDim Preserve ptMargin(ptIdx)
ptMargin(ptIdx).x = i
ptMargin(ptIdx).y = j
End If
Else
If f = 1 Then 'ÕÒµ½×îÓҵı߽çµã
f = 0
ptIdx = ptIdx + 1
ReDim Preserve ptMargin(ptIdx)
ptMargin(ptIdx).x = i - 1
ptMargin(ptIdx).y = j
End If
End If
Next
Next
'È¡ÏûÌî³ä
ExtFloodFill m_hMemDC, x, y, GetPixel(m_hMemDC, x, y), FLOODFILLSURFACE
'ÑéÖ¤½á¹û£¬Óñ߽çµãÊýÃè»æ±ß½çÏß
For i = 0 To ptIdx
SetPixelV hdc, ptMargin(i).x, ptMargin(i).y, vbRed
' Me.PSet (ptMargin(i).x, ptMargin(i).y), vbRed
Next
End Sub |
|