程序包 dev.utils.common

类 ColorUtils

java.lang.Object
dev.utils.common.ColorUtils

public final class ColorUtils extends Object
detail: 颜色工具类 ( 包括常用的色值 )
作者:
Ttt
     颜色信息和转换工具
另请参阅:
  • 嵌套类概要

    嵌套类
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static int
    alpha(int color)
    返回一个颜色中的透明度值 ( 返回十进制 )
    static float
    alphaPercent(int color)
    返回一个颜色中的透明度百分比值
    static int
    argb(float alpha, float red, float green, float blue)
    根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )
    static int
    argb(int alpha, int red, int green, int blue)
    根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )
    static int
    blendColor(int color1, int color2, float ratio)
    使用给定的比例在两种 ARGB 颜色之间进行混合
    static int
    blendColor(String color1, String color2, float ratio)
    使用给定的比例在两种 ARGB 颜色之间进行混合
    static int
    blue(int color)
    返回一个颜色中蓝色的色值 ( 返回十进制 )
    static float
    bluePercent(int color)
    返回一个颜色中蓝色的百分比值
    static int[]
    getARGB(int color)
    返回一个颜色 ARGB 色值数组 ( 返回十进制 )
    static int
    获取随机颜色值
    static int
    getRandomColor(boolean supportAlpha)
    获取随机颜色值
    static String
    获取随机颜色值字符串
    static String
    getRandomColorString(boolean supportAlpha)
    获取随机颜色值字符串
    static int
    grayLevel(int color)
    获取灰度值
    static int
    grayLevel(String colorStr)
    获取灰度值
    static int
    green(int color)
    返回一个颜色中绿色的色值 ( 返回十进制 )
    static float
    greenPercent(int color)
    返回一个颜色中绿色的百分比值
    static String
    hexAlpha(int alpha)
    获取十六进制透明度字符串
    static String
    intToArgbString(int colorInt)
    颜色值 转换 ARGB 颜色字符串
    static String
    intToRgbString(int colorInt)
    颜色值 转换 RGB 颜色字符串
    static boolean
    isARGB(int color)
    判断颜色 ARGB 是否有效
    static boolean
    isRGB(int color)
    判断颜色 RGB 是否有效
    static boolean
    判断是否为 ARGB 格式的十六进制颜色, 例如: FF990587
    static int
    parseColor(String colorStr)
    解析颜色字符串, 返回对应的颜色值
    static int
    red(int color)
    返回一个颜色中红色的色值 ( 返回十进制 )
    static float
    redPercent(int color)
    返回一个颜色中红色的百分比值
    static int
    rgb(float red, float green, float blue)
    根据对应的 red、green、blue 生成一个颜色值
    static int
    rgb(int red, int green, int blue)
    根据对应的 red、green、blue 生成一个颜色值
    static int
    setAlpha(int color, float alpha)
    设置透明度
    static int
    setAlpha(int color, int alpha)
    设置透明度
    static int
    setAlphaDark(int color, int darkValue)
    设置透明度加深
    static int
    setAlphaDark(String colorStr, int darkValue)
    设置透明度加深
    static int
    setAlphaLight(int color, int lightValue)
    设置透明度变浅
    static int
    setAlphaLight(String colorStr, int lightValue)
    设置透明度变浅
    static int
    setBlue(int color, float blue)
    改变颜色值中的蓝色色值
    static int
    setBlue(int color, int blue)
    改变颜色值中的蓝色色值
    static int
    setDark(int color, int darkValue)
    颜色加深 ( 单独修改 RGB 值, 不变动透明度 )
    static int
    setDark(String colorStr, int darkValue)
    颜色加深 ( 单独修改 RGB 值, 不变动透明度 )
    static int
    setGreen(int color, float green)
    改变颜色值中的绿色色值
    static int
    setGreen(int color, int green)
    改变颜色值中的绿色色值
    static int
    setLight(int color, int lightValue)
    颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )
    static int
    setLight(String colorStr, int lightValue)
    颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )
    static void
    设置 Color 解析器
    static int
    setRed(int color, float red)
    改变颜色值中的红色色值
    static int
    setRed(int color, int red)
    改变颜色值中的红色色值
    static void
    HSB ( HSV ) Brightness 亮度排序
    static void
    灰度值排序
    static void
    HSB ( HSV ) HUE 色相排序
    static void
    HSB ( HSV ) Saturation 饱和度排序
    static int
    transitionColor(int startColor, int endColor, float ratio)
    计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值
    static int
    transitionColor(String startColor, String endColor, float ratio)
    计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

  • 方法详细资料

    • hexAlpha

      public static String hexAlpha(int alpha)
      获取十六进制透明度字符串
      参数:
      alpha - 0-255
      返回:
      透明度 ( 十六进制 ) 值
    • getARGB

      public static int[] getARGB(int color)
      返回一个颜色 ARGB 色值数组 ( 返回十进制 )
      参数:
      color - argb/rgb color
      返回:
      ARGB 色值数组 { alpha, red, green, blue }
    • alpha

      public static int alpha(int color)
      返回一个颜色中的透明度值 ( 返回十进制 )
      参数:
      color - argb color
      返回:
      alpha 值
    • alphaPercent

      public static float alphaPercent(int color)
      返回一个颜色中的透明度百分比值
      参数:
      color - argb color
      返回:
      alpha 百分比值
    • red

      public static int red(int color)
      返回一个颜色中红色的色值 ( 返回十进制 )
      参数:
      color - argb/rgb color
      返回:
      red 值
    • redPercent

      public static float redPercent(int color)
      返回一个颜色中红色的百分比值
      参数:
      color - argb/rgb color
      返回:
      red 百分比值
    • green

      public static int green(int color)
      返回一个颜色中绿色的色值 ( 返回十进制 )
      参数:
      color - argb/rgb color
      返回:
      green 值
    • greenPercent

      public static float greenPercent(int color)
      返回一个颜色中绿色的百分比值
      参数:
      color - argb/rgb color
      返回:
      green 百分比值
    • blue

      public static int blue(int color)
      返回一个颜色中蓝色的色值 ( 返回十进制 )
      参数:
      color - argb/rgb color
      返回:
      blue 值
    • bluePercent

      public static float bluePercent(int color)
      返回一个颜色中蓝色的百分比值
      参数:
      color - argb/rgb color
      返回:
      blue 百分比值
    • rgb

      public static int rgb(int red, int green, int blue)
      根据对应的 red、green、blue 生成一个颜色值
      参数:
      red - 红色值 [0-255]
      green - 绿色值 [0-255]
      blue - 蓝色值 [0-255]
      返回:
      rgb 颜色值
    • rgb

      public static int rgb(float red, float green, float blue)
      根据对应的 red、green、blue 生成一个颜色值
      参数:
      red - 红色值 [0-255]
      green - 绿色值 [0-255]
      blue - 蓝色值 [0-255]
      返回:
      rgb 颜色值
    • argb

      public static int argb(int alpha, int red, int green, int blue)
      根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )
      参数:
      alpha - 透明度 [0-255]
      red - 红色值 [0-255]
      green - 绿色值 [0-255]
      blue - 蓝色值 [0-255]
      返回:
      argb 颜色值
    • argb

      public static int argb(float alpha, float red, float green, float blue)
      根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )
      参数:
      alpha - 透明度 [0-255]
      red - 红色值 [0-255]
      green - 绿色值 [0-255]
      blue - 蓝色值 [0-255]
      返回:
      argb 颜色值
    • isRGB

      public static boolean isRGB(int color)
      判断颜色 RGB 是否有效
      参数:
      color - rgb color
      返回:
      true yes, false no
    • isARGB

      public static boolean isARGB(int color)
      判断颜色 ARGB 是否有效
      参数:
      color - argb color
      返回:
      true yes, false no
    • setAlpha

      public static int setAlpha(int color, int alpha)
      设置透明度
      参数:
      color - argb/rgb color
      alpha - 透明度 [0-255]
      返回:
      argb 颜色值
    • setAlpha

      public static int setAlpha(int color, float alpha)
      设置透明度
      参数:
      color - argb/rgb color
      alpha - 透明度 [0-255]
      返回:
      argb 颜色值
    • setRed

      public static int setRed(int color, int red)
      改变颜色值中的红色色值
      参数:
      color - argb/rgb color
      red - 红色值 [0-255]
      返回:
      argb/rgb 颜色值
    • setRed

      public static int setRed(int color, float red)
      改变颜色值中的红色色值
      参数:
      color - argb/rgb color
      red - 红色值 [0-255]
      返回:
      argb/rgb 颜色值
    • setGreen

      public static int setGreen(int color, int green)
      改变颜色值中的绿色色值
      参数:
      color - argb/rgb color
      green - 绿色值 [0-255]
      返回:
      argb/rgb 颜色值
    • setGreen

      public static int setGreen(int color, float green)
      改变颜色值中的绿色色值
      参数:
      color - argb/rgb color
      green - 绿色值 [0-255]
      返回:
      argb/rgb 颜色值
    • setBlue

      public static int setBlue(int color, int blue)
      改变颜色值中的蓝色色值
      参数:
      color - argb/rgb color
      blue - 蓝色值 [0-255]
      返回:
      argb/rgb 颜色值
    • setBlue

      public static int setBlue(int color, float blue)
      改变颜色值中的蓝色色值
      参数:
      color - argb/rgb color
      blue - 蓝色值 [0-255]
      返回:
      argb/rgb 颜色值
    • parseColor

      public static int parseColor(String colorStr)
      解析颜色字符串, 返回对应的颜色值
           支持的格式:
           #RRGGBB
           #AARRGGBB
           'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'
       
      参数:
      colorStr - argb/rgb color String
      返回:
      argb/rgb 颜色值
    • intToRgbString

      public static String intToRgbString(int colorInt)
      颜色值 转换 RGB 颜色字符串
      参数:
      colorInt - rgb int color
      返回:
      rgb color String
    • intToArgbString

      public static String intToArgbString(int colorInt)
      颜色值 转换 ARGB 颜色字符串
      参数:
      colorInt - argb int color
      返回:
      argb color String
    • getRandomColor

      public static int getRandomColor()
      获取随机颜色值
      返回:
      随机颜色值
    • getRandomColor

      public static int getRandomColor(boolean supportAlpha)
      获取随机颜色值
      参数:
      supportAlpha - 是否支持透明度
      返回:
      argb/rgb 颜色值
    • getRandomColorString

      public static String getRandomColorString()
      获取随机颜色值字符串
      返回:
      随机颜色值
    • getRandomColorString

      public static String getRandomColorString(boolean supportAlpha)
      获取随机颜色值字符串
      参数:
      supportAlpha - 是否支持透明度
      返回:
      随机颜色值
    • judgeColorString

      public static boolean judgeColorString(String colorStr)
      判断是否为 ARGB 格式的十六进制颜色, 例如: FF990587
      参数:
      colorStr - color String
      返回:
      true yes, false no
    • setDark

      public static int setDark(String colorStr, int darkValue)
      颜色加深 ( 单独修改 RGB 值, 不变动透明度 )
      参数:
      colorStr - color String
      darkValue - 加深值
      返回:
      加深后的颜色值
    • setDark

      public static int setDark(int color, int darkValue)
      颜色加深 ( 单独修改 RGB 值, 不变动透明度 )
      参数:
      color - int color
      darkValue - 加深值
      返回:
      加深后的颜色值
    • setLight

      public static int setLight(String colorStr, int lightValue)
      颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )
      参数:
      colorStr - color String
      lightValue - 变亮 ( 变浅 ) 值
      返回:
      变亮 ( 变浅 ) 后的颜色值
    • setLight

      public static int setLight(int color, int lightValue)
      颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )
      参数:
      color - int color
      lightValue - 变亮 ( 变浅 ) 值
      返回:
      变亮 ( 变浅 ) 后的颜色值
    • setAlphaDark

      public static int setAlphaDark(String colorStr, int darkValue)
      设置透明度加深
      参数:
      colorStr - color String
      darkValue - 加深值
      返回:
      透明度加深后的颜色值
    • setAlphaDark

      public static int setAlphaDark(int color, int darkValue)
      设置透明度加深
      参数:
      color - int color
      darkValue - 加深值
      返回:
      透明度加深后的颜色值
    • setAlphaLight

      public static int setAlphaLight(String colorStr, int lightValue)
      设置透明度变浅
      参数:
      colorStr - color String
      lightValue - 变浅值
      返回:
      透明度变浅后的颜色值
    • setAlphaLight

      public static int setAlphaLight(int color, int lightValue)
      设置透明度变浅
      参数:
      color - int color
      lightValue - 变浅值
      返回:
      透明度变浅后的颜色值
    • grayLevel

      public static int grayLevel(String colorStr)
      获取灰度值
      参数:
      colorStr - color String
      返回:
      灰度值
    • grayLevel

      public static int grayLevel(int color)
      获取灰度值
      参数:
      color - int color
      返回:
      灰度值
    • setParser

      public static void setParser(ColorUtils.ColorInfo.Parser parser)
      设置 Color 解析器
      参数:
      parser - ColorUtils.ColorInfo.Parser
    • sortGray

      public static void sortGray(List<ColorUtils.ColorInfo> lists)
      灰度值排序
      参数:
      lists - 待排序颜色集合
    • sortHUE

      public static void sortHUE(List<ColorUtils.ColorInfo> lists)
      HSB ( HSV ) HUE 色相排序
      参数:
      lists - 待排序颜色集合
    • sortSaturation

      public static void sortSaturation(List<ColorUtils.ColorInfo> lists)
      HSB ( HSV ) Saturation 饱和度排序
      参数:
      lists - 待排序颜色集合
    • sortBrightness

      public static void sortBrightness(List<ColorUtils.ColorInfo> lists)
      HSB ( HSV ) Brightness 亮度排序
      参数:
      lists - 待排序颜色集合
    • blendColor

      public static int blendColor(String color1, String color2, float ratio)
      使用给定的比例在两种 ARGB 颜色之间进行混合
      参数:
      color1 - 第一种 ARGB 颜色
      color2 - 第二种 ARGB 颜色
      ratio - 两种颜色混合比例
      返回:
      混合后的颜色
    • blendColor

      public static int blendColor(int color1, int color2, float ratio)
      使用给定的比例在两种 ARGB 颜色之间进行混合
           android.support.v4.graphics.ColorUtils#blendARGB
           混合比:
           0.0 将产生 color1
           0.5 将产生均匀的混合
           1.0 将产生 color2
       
      参数:
      color1 - 第一种 ARGB 颜色
      color2 - 第二种 ARGB 颜色
      ratio - 两种颜色混合比例
      返回:
      混合后的颜色
    • transitionColor

      public static int transitionColor(String startColor, String endColor, float ratio)
      计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值
      参数:
      startColor - 开始颜色值
      endColor - 结束颜色值
      ratio - 过渡百分比
      返回:
      计算后颜色值
    • transitionColor

      public static int transitionColor(int startColor, int endColor, float ratio)
      计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值
      参数:
      startColor - 开始颜色值
      endColor - 结束颜色值
      ratio - 过渡百分比
      返回:
      计算后颜色值