'0<=混合率<=1 Dim C1 as long,C2 as long Dim R1 as integer,G1 as integer,B1 as integer Dim R2 as integer,G2 as integer,B2 as integer Dim R3 as integer,G3 as integer,B3 as integerC1=Label1.BackColor C2=Label2.BackColorR1=C1 And &hFF G1=(C1 And &HFF00&)\&h100 B1=(C1 And &hFF0000)\&h10000R2=C2 And &hFF G2=(C2 And &HFF00&)\&h100 B2=(C2 And &hFF0000)\&h10000R3=R1+(R2-R1)*混合率 If R3<0 Then R3=0 If R3>255 Then R3=255 G3=G1+(G2-G1)*混合率 If G3<0 Then R3=0 If G3>255 Then G3=255 B3=B1+(B2-B1)*混合率 If B3<0 Then R3=0 If B3>255 Then B3=255Label3.BackColor=RGB(R3,G3,B3)
Private Sub HScrR_Change() Call HScrR_Scroll End SubPrivate Sub HScrR_Scroll() r = HScrR.Value Call SubColor End Sub Private Sub HScrG_Change() Call HScrG_Scroll End SubPrivate Sub HScrG_Scroll() g = HScrG.Value Call SubColor End Sub Private Sub HScrB_Change() Call HScrB_Scroll End SubPrivate Sub HScrB_Scroll() b = HScrB.Value Call SubColor End SubPrivate Sub SubColor() HScrR.Value = r HScrG.Value = g HScrB.Value = b Picture1.BackColor = RGB(r, g, b) LabRB.BackColor = RGB(r, 0, 0) LabGB.BackColor = RGB(0, g, 0) LabBB.BackColor = RGB(0, 0, b) End Sub
比如你的两种颜色各占一半混合,那就把第一种颜色的RGB分量分别除以2然后再加上另一种颜色的RGB分量的1/2,最后再用rgb函数将计算得到的三个分量合成颜色代码。
Dim C1 as long,C2 as long
Dim R1 as integer,G1 as integer,B1 as integer
Dim R2 as integer,G2 as integer,B2 as integer
Dim R3 as integer,G3 as integer,B3 as integerC1=Label1.BackColor
C2=Label2.BackColorR1=C1 And &hFF
G1=(C1 And &HFF00&)\&h100
B1=(C1 And &hFF0000)\&h10000R2=C2 And &hFF
G2=(C2 And &HFF00&)\&h100
B2=(C2 And &hFF0000)\&h10000R3=R1+(R2-R1)*混合率
If R3<0 Then R3=0
If R3>255 Then R3=255
G3=G1+(G2-G1)*混合率
If G3<0 Then R3=0
If G3>255 Then G3=255
B3=B1+(B2-B1)*混合率
If B3<0 Then R3=0
If B3>255 Then B3=255Label3.BackColor=RGB(R3,G3,B3)
Call HScrR_Scroll
End SubPrivate Sub HScrR_Scroll()
r = HScrR.Value
Call SubColor
End Sub
Private Sub HScrG_Change()
Call HScrG_Scroll
End SubPrivate Sub HScrG_Scroll()
g = HScrG.Value
Call SubColor
End Sub
Private Sub HScrB_Change()
Call HScrB_Scroll
End SubPrivate Sub HScrB_Scroll()
b = HScrB.Value
Call SubColor
End SubPrivate Sub SubColor()
HScrR.Value = r
HScrG.Value = g
HScrB.Value = b
Picture1.BackColor = RGB(r, g, b)
LabRB.BackColor = RGB(r, 0, 0)
LabGB.BackColor = RGB(0, g, 0)
LabBB.BackColor = RGB(0, 0, b)
End Sub