颜色 [英] Colors
问题描述
是否有一种简单的方法可以获得较浅或较暗的颜色版本?
我可以转换为HSL并更改L值然后转换回来。
或者我可以将RGB值上调或下调预定量。
有关最佳方法的建议吗?谢谢。
Jerry
Is there a simple way to get a lighter or darker version of a color?
I can convert to HSL and change the L value and then convert back.
Or I can just bump the RGB values up or down by a predetermined amount.
Any advice on the best way? Thanks.
Jerry
推荐答案
Jerry Camel< rl ***** @ msn.com> ;写在
新闻:#f ************** @ TK2MSFTNGP12.phx.gbl:
Jerry Camel <rl*****@msn.com> wrote in
news:#f**************@TK2MSFTNGP12.phx.gbl:
是否有获得浅色或深色版本的简单方法?
我可以转换为HSL并更改L值然后转换回来。
或者我只需按预定的数量上调或下调RGB值。
Is there a simple way to get a lighter or darker version
of a color?
I can convert to HSL and change the L value and then convert back.
Or I can just bump the RGB values up or down by a predetermined
amount.
试试这个。
共享函数混合(ByVal C1 As Color, ByVal C2 As Color,ByVal P1 As
Single)As Color
Dim R1 As Single = C1.R * P1
Dim G1 As Single = C1.G * P1
Dim B1单身= C1.B * P1
Dim R2单身= C2.R *(1 - P1)
Dim G2单身= C2.G *(1 - P1)
Dim B2单身= C2.B *(1 - P1)
Blend = Color.FromArgb(CInt(R1 + R2),CInt(G1 + G2),CInt(B1 + B2))
结束功能
共享功能增亮(ByVal C As Color,ByVal Percent as Single)As
颜色
如果百分比< = 0则返回C
Dim HSL As new colorHSL(C)
Dim L As Single
L = HSL.Lum +(HSLMAX *百分比)
如果L> HSLMAX然后L = HSLMAX
HSL.Lum = L
亮= HSL.ColorValue
结束功能
共享功能变暗(ByVal C为颜色,ByVal百分比为单)为
颜色
如果百分比< = 0则返回C
Dim HSL As new colorHSL(C)
Dim L As Single
L = HSL.Lum - (HSLMAX *百分比)
如果L< 0然后L = 0
HSL.Lum = L
变暗= HSL.ColorValue
结束功能
kpg
try this.
Shared Function Blend(ByVal C1 As Color, ByVal C2 As Color, ByVal P1 As
Single) As Color
Dim R1 As Single = C1.R * P1
Dim G1 As Single = C1.G * P1
Dim B1 As Single = C1.B * P1
Dim R2 As Single = C2.R * (1 - P1)
Dim G2 As Single = C2.G * (1 - P1)
Dim B2 As Single = C2.B * (1 - P1)
Blend = Color.FromArgb(CInt(R1 + R2), CInt(G1 + G2), CInt(B1 + B2))
End Function
Shared Function Brighten(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum + (HSLMAX * Percent)
If L > HSLMAX Then L = HSLMAX
HSL.Lum = L
Brighten = HSL.ColorValue
End Function
Shared Function Darken(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum - (HSLMAX * Percent)
If L < 0 Then L = 0
HSL.Lum = L
Darken = HSL.ColorValue
End Function
kpg
你在哪里获得ColorHSL?那是你自己的班级吗?
" kpg" < ipost @ thereforeiam>在消息中写道
news:Xn ******************************* @ 127.0.0.1。 。
Where are you getting the ColorHSL? Is that your own class?
"kpg" <ipost@thereforeiam> wrote in message
news:Xn*******************************@127.0.0.1.. .
Jerry Camel< rl ***** @ msn.com>在
新闻中写道:#f ************** @ TK2MSFTNGP12.phx.gbl:
Jerry Camel <rl*****@msn.com> wrote in
news:#f**************@TK2MSFTNGP12.phx.gbl:
有没有一种简单的方法可以获得一个颜色较浅或较暗的颜色?
我可以转换为HSL并更改L值然后转换回来。
或者我可以碰到它RGB值上升或下降预定的数量。
Is there a simple way to get a lighter or darker version
of a color?
I can convert to HSL and change the L value and then convert back.
Or I can just bump the RGB values up or down by a predetermined
amount.
试试这个。
共享功能混合(ByVal C1作为颜色,ByVal C2作为颜色,ByVal P1 As
单色)作为颜色
Dim R1单个= C1.R * P1
Dim G1单个= C1.G * P1
Dim B1单个= C1 .B * P1
Dim R2单一= C2.R *(1 - P1)
Dim G2单一= C2.G *(1 - P1)
Dim B2单一= C2 .B *(1 - P1)
Blend = Color.FromArgb(CInt(R1 + R2),CInt(G1 + G2),CInt(B1 + B2))
结束功能
共享功能增亮(ByVal C为颜色,ByVal百分比为单)为
颜色
如果百分比< = 0则返回C
Dim HSL为新颜色HSL(C)
如果L> HSLMAX然后L = HSLMAX
HSL.Lum = L
亮度= HSL.ColorValue
结束功能
共享功能变暗(ByVal C为颜色,ByVal百分比为单)如颜色
如果百分比< = 0则返回C
Dim HSL为新颜色HSL(C)
Dim L As Single
L = HSL.Lum - (HSLMAX *百分比)
如果L< 0然后L = 0
HSL.Lum = L
Darken = HSL.ColorValue
结束功能
kpg
try this.
Shared Function Blend(ByVal C1 As Color, ByVal C2 As Color, ByVal P1 As
Single) As Color
Dim R1 As Single = C1.R * P1
Dim G1 As Single = C1.G * P1
Dim B1 As Single = C1.B * P1
Dim R2 As Single = C2.R * (1 - P1)
Dim G2 As Single = C2.G * (1 - P1)
Dim B2 As Single = C2.B * (1 - P1)
Blend = Color.FromArgb(CInt(R1 + R2), CInt(G1 + G2), CInt(B1 + B2))
End Function
Shared Function Brighten(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum + (HSLMAX * Percent)
If L > HSLMAX Then L = HSLMAX
HSL.Lum = L
Brighten = HSL.ColorValue
End Function
Shared Function Darken(ByVal C As Color, ByVal Percent As Single) As
Color
If Percent <= 0 Then Return C
Dim HSL As New colorHSL(C)
Dim L As Single
L = HSL.Lum - (HSLMAX * Percent)
If L < 0 Then L = 0
HSL.Lum = L
Darken = HSL.ColorValue
End Function
kpg
Rlrcstr< rl ***** @ msn.com>写在
新闻:ee ************** @ TK2MSFTNGP12.phx.gbl:
Rlrcstr <rl*****@msn.com> wrote in
news:ee**************@TK2MSFTNGP12.phx.gbl:
你在哪里得到ColorHSL?这是你自己的课吗?
Where are you getting the ColorHSL? Is that your own
class?
是的。抱歉。这是一堂课,但我没有写。
我找不到作者的名字,所以我犹豫
发布它它的整体性。这是相当老的,我认为
我从psc或类似的东西得到它 - 但重新搜索转向
没什么。
如何令人尴尬。
kpg
Yes. Sorry. It is a class, but I did not write it.
I can''t locate the authors name, so I am hesitant to
post it in its entirity. It is rather old and I think
I got it from psc or the like - but a re-search turned
up nothing.
How embarrassing.
kpg
这篇关于颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!