码迷,mamicode.com
首页 > 其他好文 > 详细

e585. Converting Between RGB and HSB Colors

时间:2018-09-02 23:44:05      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:bsp   ffffff   style   strong   gre   org   and   example   ati   

This example demonstrates how to convert between a color value in RGB (three integer values in the range 0 to 255 representing red, green, and blue) and HSB (three floating point values in the range 0 to 1.0 representing hue, saturation, and brightness).

    // Specify 3 RGB values
    int red = 0x33;
    int green = 0x66;
    int blue = 0x99;
    
    // Convert RGB to HSB
    float[] hsb = Color.RGBtoHSB(red, green, blue, null);
    float hue = hsb[0];          // .58333
    float saturation = hsb[1];   // .66667
    float brightness = hsb[2];   // .6
    
    // Convert HSB to RGB value
    int rgb = Color.HSBtoRGB(hue, saturation, brightness);
    red = (rgb>>16)&0xFF;
    green = (rgb>>8)&0xFF;
    blue = rgb&0xFF;

 

Related Examples

e585. Converting Between RGB and HSB Colors

标签:bsp   ffffff   style   strong   gre   org   and   example   ati   

原文地址:https://www.cnblogs.com/borter/p/9575652.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!