[此贴子已经被作者于2007-4-2 23:05:36编辑过]
来看看...这个我也想知道..
楼下的朋友 请...
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Sub Command1_Click()
Dim lColor1 As Long, lColor2 As Long, lColor3 As Long
Dim iR1 As Long, iG1 As Long, iB1 As Long
Dim iR2 As Long, iG2 As Long, iB2 As Long
Dim iR3 As Long, iG3 As Long, iB3 As Long
Dim i As Long, j As Long, k As Long
For k = 127 To 127'K值是用来决定透明度的,值为0-255,我0-255,127时为50%
For i = 0 To pic1.ScaleWidth - 1
For j = 0 To pic1.ScaleHeight - 1
lColor1 = GetPixel(pic1.hdc, i, j)
iR1 = lColor1 And &HFF
iG1 = (lColor1 \ &H100) And &HFF
iB1 = (lColor1 \ &H10000) And &HFF
DoEvents
lColor2 = GetPixel(pic2.hdc, i, j)
iR2 = lColor2 And &HFF
iG2 = (lColor2 \ &H100) And &HFF
iB2 = (lColor2 \ &H10000) And &HFF
DoEvents
'对应像素点的合成公式(k的取值在0~255之间)这里是关键
iR3 = (iR1 * (255 - k) + iR2 * k) / 255
iG3 = (iG1 * (255 - k) + iG2 * k) / 255
iB3 = (iB1 * (255 - k) + iB2 * k) / 255
lColor3 = RGB(iR3, iG3, iB3)
SetPixel pic3.hdc, i, j, lColor3
Next j
Next i
pic3.Refresh
'SavePicture pic3.Image, App.Path & "\pic\" & Trim(Str(k)) & ".bmp"
Form1.Caption = Left(Str(k / 255), 5) & "%"
DoEvents ': pic3.Cls
Next k
End Sub
Private Sub Command2_Click() '交叉画点的方法
Dim i As Integer, j As Integer
For i = 0 To pic1.ScaleWidth - 1
For j = 0 To pic1.ScaleHeight - 1
If (j Mod 2 = 0) And (i Mod 2 <> 0) Then
SetPixel pic3.hdc, i, j, GetPixel(pic1.hdc, i, j)
ElseIf (j Mod 2 <> 0) And (i Mod 2 = 0) Then
SetPixel pic3.hdc, i, j, GetPixel(pic2.hdc, i, j)
End If
Next j
Next i
pic3.Refresh
End Sub
[此贴子已经被作者于2007-4-7 21:00:06编辑过]