| 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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)
Private Type RGBAComponent
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type
Sub MixPictures(pctTarget As PictureBox, pctSource1 As PictureBox, _
nSrcX1 As Long, nSrcY1 As Long, nWidth As Long, nHeight As Long, _
pctSource2 As PictureBox, nSrcX2 As Long, nSrcY2 As Long, _
nValue1 As Long)
Dim nValue2 As Long
nValue2 = 255 - nValue1
Dim nCurColor1 As Long
Dim nCurColor2 As Long
Dim rgba1 As RGBAComponent
Dim rgba2 As RGBAComponent
Dim X As Long
Dim Y As Long
For Y = nSrcY1 To nSrcY1 + nHeight
For X = nSrcX1 To nSrcX1 + nWidth
nCurColor1 = GetPixel(pctSource1.hdc, X, Y)
nCurColor2 = GetPixel(pctSource2.hdc, _
X + nSrcX2 - nSrcX1, Y + nSrcY2 - nSrcY1)
CopyMemory rgba1, nCurColor1, 4
CopyMemory rgba2, nCurColor2, 4
SetPixel pctTarget.hdc, X - nSrcX1, Y - nSrcY1, _
RGB((rgba1.Red * nValue1 + rgba2.Red * nValue2) \ 255, _
(rgba1.Green * nValue1 + rgba2.Green * nValue2) \ 255, _
(rgba1.Blue * nValue1 + rgba2.Blue * nValue2) \ 255)
Next
Next
End Sub
|
| MixPictures Picture3, Picture1, 0, 0, Picture1.Width / _
Screen.TwipsPerPixelX, Picture2.Height / _
Screen.TwipsPerPixelY, Picture2, 0, 0, HScroll1.Value
|