这是我做的,部分代码 你看看吧 用API函数GetPixel,SetPixelV Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crcolour As Long) As Long Sub ruihua(ByVal ha&, ByVal hd&, ByVal w, ByVal h) Dim c1, c2, c3, c4, c5, c As Long Dim x0, y0 As Long Dim r, g, b As Long Screen.MousePointer = 11 For x0 = 0 To w For y0 = 0 To h c1 = GetPixel(ha, x0, y0) c2 = GetPixel(ha, x0 + 1, y0) c3 = GetPixel(ha, x0, y0 + 1) c4 = c3 - c1 c5 = c2 - c1 If c4 > c5 Then c = c4 Else c = c5 End If r = (c And &HFF) g = (c And 62580) / 256 b = (c And &HFF0000) / 256 If r > 255 Then r = 255 ElseIf r < 0 Then r = 0 End If If g > 255 Then g = 255 ElseIf g < 0 Then g = 0 End If If b > 255 Then b = 255 ElseIf b < 0 Then b = 0 End If SetPixelV hd, x0, y0, RGB(r, g, b) 'DoEvents Next y0 Next x0 Screen.MousePointer = 0 End Sub
慢慢看,希望对你有用
你看看吧
用API函数GetPixel,SetPixelV
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crcolour As Long) As Long
Sub ruihua(ByVal ha&, ByVal hd&, ByVal w, ByVal h)
Dim c1, c2, c3, c4, c5, c As Long
Dim x0, y0 As Long
Dim r, g, b As Long
Screen.MousePointer = 11
For x0 = 0 To w
For y0 = 0 To h
c1 = GetPixel(ha, x0, y0)
c2 = GetPixel(ha, x0 + 1, y0)
c3 = GetPixel(ha, x0, y0 + 1)
c4 = c3 - c1
c5 = c2 - c1
If c4 > c5 Then
c = c4
Else
c = c5
End If
r = (c And &HFF)
g = (c And 62580) / 256
b = (c And &HFF0000) / 256
If r > 255 Then
r = 255
ElseIf r < 0 Then
r = 0
End If
If g > 255 Then
g = 255
ElseIf g < 0 Then
g = 0
End If
If b > 255 Then
b = 255
ElseIf b < 0 Then
b = 0
End If
SetPixelV hd, x0, y0, RGB(r, g, b)
'DoEvents
Next y0
Next x0
Screen.MousePointer = 0
End Sub