Здравствуйте, уважаемые.
Имеется картинка, пользователь должен иметь возможность изменять её цвет двигая слайдеры R,G и B. Как это реализовать?
Заранее спасибо
Георгий
' ïðåîáðàçóåò RGB â HSV
Private Sub CalcHSV()
Dim sngRed As Single
Dim sngGreen As Single
Dim sngBlue As Single
Dim sngMx As Single
Dim sngMn As Single
Dim sngDelta As Single
Dim sngVa As Single
Dim sngSa As Single
Dim sngRc As Single
Dim sngGc As Single
Dim sngBc As Single
sngRed = mintRed / 255
sngGreen = mintGreen / 255
sngBlue = mintBlue / 255
sngMx = sngRed
If sngGreen > sngMx Then sngMx = sngGreen
If sngBlue > sngMx Then sngMx = sngBlue
sngMn = sngRed
If sngGreen < sngMn Then sngMn = sngGreen
If sngBlue < sngMn Then sngMn = sngBlue
sngDelta = sngMx - sngMn
sngVa = sngMx
If sngMx Then
sngSa = sngDelta / sngMx
Else
sngSa = 0
End If
If sngSa = 0 Then
msngHue = 0
Else
sngRc = (sngMx - sngRed) / sngDelta
sngGc = (sngMx - sngGreen) / sngDelta
sngBc = (sngMx - sngBlue) / sngDelta
Select Case sngMx
Case sngRed
msngHue = sngBc - sngGc
Case sngGreen
msngHue = 2 + sngRc - sngBc
Case sngBlue
msngHue = 4 + sngGc - sngRc
End Select
msngHue = msngHue * 60
If msngHue < 0 Then msngHue = msngHue + 360
End If
msngSaturation = sngSa * 100
msngValue = sngVa * 100
End Sub
' ïðåîáðàçóåò HSV â RGB
Private Sub CalcRGB()
Dim sngSaturation As Single
Dim sngValue As Single
Dim sngHue As Single
Dim intl As Integer
Dim sngF As Single
Dim sngP As Single
Dim sngQ As Single
Dim sngT As Single
Dim sngRed As Single
Dim sngGreen As Single
Dim sngBlue As Single
sngSaturation = msngSaturation / 100
sngValue = msngValue / 100
If msngSaturation = 0 Then
sngRed = sngValue
sngGreen = sngValue
sngBlue = sngValue
Else
sngHue = msngHue / 60
If sngHue = 6 Then sngHue = 0
intl = Int(sngHue)
sngF = sngHue - intl
sngP = sngValue * (1! - sngSaturation)
sngQ = sngValue * (1! - (sngSaturation * sngF))
sngT = sngValue * (1! - (sngSaturation * (1! - sngF)))
Select Case intl
Case 0
sngRed = sngValue
sngGreen = sngT
sngBlue = sngP
Case 1
sngRed = sngQ
sngGreen = sngValue
sngBlue = sngP
Case 2
sngRed = sngP
sngGreen = sngValue
sngBlue = sngT
Case 3
sngRed = sngP
sngGreen = sngQ
sngBlue = sngValue
Case 4
sngRed = sngT
sngGreen = sngP
sngBlue = sngValue
Case 5
sngRed = sngValue
sngGreen = sngP
sngBlue = sngQ
End Select
End If
mintRed = Int(255.9999 * sngRed)
mintGreen = Int(255.9999 * sngGreen)
mintBlue = Int(255.9999 * sngBlue)
End Sub
заюзать стандартные АПИ ColorRGBToHLS и ColorHLSToRGB
Сейчас этот форум просматривают: Google-бот и гости: 47