Reference:Android.graphics.Color

From Triled Wiki

Jump to: navigation, search


android.graphics
public class android.graphics.Color

java.lang.Object
android.graphics.Color

The Color class defines methods for creating and converting color ints. Colors are represented as packed ints, made up of 4 bytes: alpha, red, green, blue. The values are unpremultiplied, meaning any transparency is stored solely in the alpha component, and not in the color components. The components are stored as follows (alpha << 24) | (red << 16) | (green << 8) | blue. Each component ranges between 0..255 with 0 meaning no contribution for that component, and 255 meaning 100% contribution. Thus opaque-black would be 0xFF000000 (100% opaque but no contributes from red, gree, blue, and opaque-white would be 0xFFFFFFFF

Contents

[edit] Summary

[edit] Constants

      Value  
int  BLACK     -16777216  0xff000000 
int  BLUE     -16776961  0xff0000ff 
int  CYAN     -16711681  0xff00ffff 
int  DKGRAY     -12303292  0xff444444 
int  GRAY     -7829368  0xff888888 
int  GREEN     -16711936  0xff00ff00 
int  LTGRAY     -3355444  0xffcccccc 
int  MAGENTA     -65281  0xffff00ff 
int  RED     -65536  0xffff0000 
int  TRANSPARENT     0x00000000 
int  WHITE     -1  0xffffffff 
int  YELLOW     -256  0xffffff00 

[edit] Public Constructors

          Color ()

[edit] Public Methods

      static  int  HSVToColor (int alpha, float[] hsv)
Convert HSV components to an ARGB color.
      static  int  HSVToColor (float[] hsv)
Convert HSV components to an ARGB color.
      static  void  RGBToHSV (int red, int green, int blue, float[] hsv)
Convert RGB components to HSV.
      static  int  alpha (int color)
Return the alpha component of a color int.
      static  int  argb (int alpha, int red, int green, int blue)
Return a color-int from alpha, red, green, blue components.
      static  int  blue (int color)
Return the blue component of a color int.
      static  void  colorToHSV (int color, float[] hsv)
Convert the argb color to its HSV components.
      static  int  green (int color)
Return the green component of a color int.
      static  int  parseColor (String colorString)
Parse the color string, and return the corresponding color-int.
      static  int  red (int color)
Return the red component of a color int.
      static  int  rgb (int red, int green, int blue)
Return a color-int from red, green, blue components.

[edit] Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

[edit] Details

[edit] Constants

[edit] public static final int BLACK

Constant Value: -16777216 (0xff000000)

[edit] public static final int BLUE

Constant Value: -16776961 (0xff0000ff)

[edit] public static final int CYAN

Constant Value: -16711681 (0xff00ffff)

[edit] public static final int DKGRAY

Constant Value: -12303292 (0xff444444)

[edit] public static final int GRAY

Constant Value: -7829368 (0xff888888)

[edit] public static final int GREEN

Constant Value: -16711936 (0xff00ff00)

[edit] public static final int LTGRAY

Constant Value: -3355444 (0xffcccccc)

[edit] public static final int MAGENTA

Constant Value: -65281 (0xffff00ff)

[edit] public static final int RED

Constant Value: -65536 (0xffff0000)

[edit] public static final int TRANSPARENT

Constant Value: 0 (0x00000000)

[edit] public static final int WHITE

Constant Value: -1 (0xffffffff)

[edit] public static final int YELLOW

Constant Value: -256 (0xffffff00)

[edit] Public Constructors

[edit] public Color()

[edit] Public Methods

[edit] public static int HSVToColor(int alpha, float[] hsv)

Convert HSV components to an ARGB color. The alpha component is passed through unchanged. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.

Parameters

alpha the alpha component of the returned argb color.
hsv 3 element array which holds the input HSV components.

Returns

  • the resulting argb color

[edit] public static int HSVToColor(float[] hsv)

Convert HSV components to an ARGB color. Alpha set to 0xFF. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1] If hsv values are out of range, they are pinned.

Parameters

hsv 3 element array which holds the input HSV components.

Returns

  • the resulting argb color

[edit] public static void RGBToHSV(int red, int green, int blue, float[] hsv)

Convert RGB components to HSV. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]

Parameters

red red component value [0..255]
green green component value [0..255]
blue blue component value [0..255]
hsv 3 element array which holds the resulting HSV components.

[edit] public static int alpha(int color)

Return the alpha component of a color int. This is the same as saying color >>> 24

[edit] public static int argb(int alpha, int red, int green, int blue)

Return a color-int from alpha, red, green, blue components. These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.

Parameters

alpha Alpha component [0..255] of the color
red Red component [0..255] of the color
green Green component [0..255] of the color
blue Blue component [0..255] of the color

[edit] public static int blue(int color)

Return the blue component of a color int. This is the same as saying color & 0xFF

[edit] public static void colorToHSV(int color, float[] hsv)

Convert the argb color to its HSV components. hsv[0] is Hue [0 .. 360) hsv[1] is Saturation [0...1] hsv[2] is Value [0...1]

Parameters

color the argb color to convert. The alpha component is ignored.
hsv 3 element array which holds the resulting HSV components.

[edit] public static int green(int color)

Return the green component of a color int. This is the same as saying (color >> 8) & 0xFF

[edit] public static int parseColor(String colorString)

Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'

[edit] public static int red(int color)

Return the red component of a color int. This is the same as saying (color >> 16) & 0xFF

[edit] public static int rgb(int red, int green, int blue)

Return a color-int from red, green, blue components. The alpha component is implicity 255 (fully opaque). These component values should be [0..255], but there is no range check performed, so if they are out of range, the returned color is undefined.

Parameters

red Red component [0..255] of the color
green Green component [0..255] of the color
blue Blue component [0..255] of the color

[edit] References

Personal tools