Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Dim hbrush As Long Dim holdbrush As Long Dim color As Long Picture1.ScaleMode = 3 'API函数需要 '(x,y)为要填充某个封闭区域里的任意一点 color = GetPixel(Picture1.hdc, x, y)'颜色取样 hbrush = CreateSolidBrush(欲填充的颜色) '创建刷子 holdbrush = SelectObject(Picture1.hdc, hbrush) '选入设备场景 ExtFloodFill Picture1.hdc, x, y, color, 1 '该函数从指定的点(x,y)向外填充,只要找到了Color,因而会一直填到区域的边沿。 SelectObject Picture1.hdc, holdbrush DeleteObject hbrush '删除创建的刷子
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function ExtFloodFill Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long, ByVal wFillType As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Dim hbrush As Long
Dim holdbrush As Long
Dim color As Long
Picture1.ScaleMode = 3 'API函数需要
'(x,y)为要填充某个封闭区域里的任意一点
color = GetPixel(Picture1.hdc, x, y)'颜色取样
hbrush = CreateSolidBrush(欲填充的颜色) '创建刷子
holdbrush = SelectObject(Picture1.hdc, hbrush) '选入设备场景
ExtFloodFill Picture1.hdc, x, y, color, 1 '该函数从指定的点(x,y)向外填充,只要找到了Color,因而会一直填到区域的边沿。
SelectObject Picture1.hdc, holdbrush
DeleteObject hbrush '删除创建的刷子