CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  多媒体

有关一个亮度的问题

楼主kwxx(东京大屠杀万岁!)2005-08-03 23:34:10 在 VB / 多媒体 提问

通过一个WINDOWS的标准调色板,RGB=0,0,255可以得到一个标准的蓝色,显示的亮度是120;而一个RGB=100,100,255的颜色同样是蓝色,不过亮度是167。此时,如果在调色板里把167的亮度改回120,又可以得到RGB=0,0,255的标准蓝色了,说明这两个颜色只是亮度不同,色调是相同的。如果任意给一个颜色RGB=X,Y,Z,可以求出它的亮度L,如果此时指定一个亮度L',问当亮度为L'时相同色调的颜色的X,Y,Z分别是多少? 问题点数:41、回复次数:4Top

1 楼kwxx(东京大屠杀万岁!)回复于 2005-08-03 23:59:22 得分 0

或者有哪位高手提供RGB转到色调和饱和度的代码也可以。上面所需要的只改变亮度色调与饱和度是不变的。Top

2 楼kwxx(东京大屠杀万岁!)回复于 2005-08-07 00:55:52 得分 0

upTop

3 楼fishmans(金脚指)回复于 2005-08-07 01:02:37 得分 41

[转贴]  
  代码~  
   
  Private   Sub   RGBToHSL(   _  
              r   As   Long,   g   As   Long,   b   As   Long,   _  
              h   As   Single,   s   As   Single,   l   As   Single   _  
        )  
  Dim   Max   As   Single  
  Dim   Min   As   Single  
  Dim   delta   As   Single  
  Dim   rR   As   Single,   rG   As   Single,   rB   As   Single  
   
        rR   =   r   /   255:   rG   =   g   /   255:   rB   =   b   /   255  
   
  '{Given:   rgb   each   in   [0,1].  
  '   Desired:   h   in   [0,360]   and   s   in   [0,1],   except   if   s=0,   then   h=UNDEFINED.}  
                  Max   =   Maximum(rR,   rG,   rB)  
                  Min   =   Minimum(rR,   rG,   rB)  
                  l   =   (Max   +   Min)   /   2         '{This   is   the   lightness}  
                  '{Next   calculate   saturation}  
                  If   Max   =   Min   Then  
                          'begin   {Acrhomatic   case}  
                          s   =   0  
                          h   =   0  
                        'end   {Acrhomatic   case}  
                  Else  
                        'begin   {Chromatic   case}  
                                  '{First   calculate   the   saturation.}  
                        If   l   <=   0.5   Then  
                                s   =   (Max   -   Min)   /   (Max   +   Min)  
                        Else  
                                s   =   (Max   -   Min)   /   (2   -   Max   -   Min)  
                          End   If  
                          '{Next   calculate   the   hue.}  
                          delta   =   Max   -   Min  
                        If   rR   =   Max   Then  
                                  h   =   (rG   -   rB)   /   delta         '{Resulting   color   is   between   yellow   and   magenta}  
                        ElseIf   rG   =   Max   Then  
                                  h   =   2   +   (rB   -   rR)   /   delta   '{Resulting   color   is   between   cyan   and   yellow}  
                        ElseIf   rB   =   Max   Then  
                                  h   =   4   +   (rR   -   rG)   /   delta   '{Resulting   color   is   between   magenta   and   cyan}  
                          End   If  
                          'Debug.Print   h  
                          'h   =   h   *   60  
                        'If   h   <   0#   Then  
                        '           h   =   h   +   360                         '{Make   degrees   be   nonnegative}  
                        'End   If  
                  'end   {Chromatic   Case}  
              End   If  
  'end   {RGB_to_HLS}  
  End   Sub  
   
  Public   Sub   HLSToRGB(   _  
              h   As   Single,   s   As   Single,   l   As   Single,   _  
              r   As   Long,   g   As   Long,   b   As   Long   _  
        )  
  Dim   rR   As   Single,   rG   As   Single,   rB   As   Single  
  Dim   Min   As   Single,   Max   As   Single  
   
        If   s   =   0   Then  
              '   Achromatic   case:  
              rR   =   l:   rG   =   l:   rB   =   l  
        Else  
              '   Chromatic   case:  
              '   delta   =   Max-Min  
              If   l   <=   0.5   Then  
                    's   =   (Max   -   Min)   /   (Max   +   Min)  
                    '   Get   Min   value:  
                    Min   =   l   *   (1   -   s)  
              Else  
                    's   =   (Max   -   Min)   /   (2   -   Max   -   Min)  
                    '   Get   Min   value:  
                    Min   =   l   -   s   *   (1   -   l)  
              End   If  
              '   Get   the   Max   value:  
              Max   =   2   *   l   -   Min  
               
              '   Now   depending   on   sector   we   can   evaluate   the   h,l,s:  
              If   (h   <   1)   Then  
                    rR   =   Max  
                    If   (h   <   0)   Then  
                          rG   =   Min  
                          rB   =   rG   -   h   *   (Max   -   Min)  
                    Else  
                          rB   =   Min  
                          rG   =   h   *   (Max   -   Min)   +   rB  
                    End   If  
              ElseIf   (h   <   3)   Then  
                    rG   =   Max  
                    If   (h   <   2)   Then  
                          rB   =   Min  
                          rR   =   rB   -   (h   -   2)   *   (Max   -   Min)  
                    Else  
                          rR   =   Min  
                          rB   =   (h   -   2)   *   (Max   -   Min)   +   rR  
                    End   If  
              Else  
                    rB   =   Max  
                    If   (h   <   4)   Then  
                          rR   =   Min  
                          rG   =   rR   -   (h   -   4)   *   (Max   -   Min)  
                    Else  
                          rG   =   Min  
                          rR   =   (h   -   4)   *   (Max   -   Min)   +   rG  
                    End   If  
                     
              End   If  
                           
        End   If  
        r   =   rR   *   255:   g   =   rG   *   255:   b   =   rB   *   255  
  End   Sub  
  Private   Function   Maximum(rR   As   Single,   rG   As   Single,   rB   As   Single)   As   Single  
        If   (rR   >   rG)   Then  
              If   (rR   >   rB)   Then  
                    Maximum   =   rR  
              Else  
                    Maximum   =   rB  
              End   If  
        Else  
              If   (rB   >   rG)   Then  
                    Maximum   =   rB  
              Else  
                    Maximum   =   rG  
              End   If  
        End   If  
  End   Function  
  Private   Function   Minimum(rR   As   Single,   rG   As   Single,   rB   As   Single)   As   Single  
        If   (rR   <   rG)   Then  
              If   (rR   <   rB)   Then  
                    Minimum   =   rR  
              Else  
                    Minimum   =   rB  
              End   If  
        Else  
              If   (rB   <   rG)   Then  
                    Minimum   =   rB  
              Else  
                    Minimum   =   rG  
              End   If  
        End   If  
  End   Function  
   
  Top

4 楼kwxx(东京大屠杀万岁!)回复于 2005-08-09 09:35:46 得分 0

谢了楼上的,我已经找到了这个算法,并且已经实现了。还是感谢!Top

相关问题

  • 如何高亮度显示??
  • datagGrid高亮度显示?
  • 对比度与亮度?
  • 求C#亮度算法
  • 更改圖片亮度的方法
  • 如何调整realone的亮度?
  • RGB与(亮度,对比度)的关系?
  • 关于界面颜色和亮度
  • 请教如何清除高亮度条
  • 如何调节图片亮度?

关键词

  • 亮度
  • singledim
  • rg
  • 色调
  • rgb
  • rr
  • single
  • 颜色
  • rb
  • 蓝色

得分解答快速导航

  • 帖主:kwxx
  • fishmans

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo