public sealed class Color : IMessage<Color>, IEquatable<Color>, IDeepCloneable<Color>, IBufferMessage, IMessage
Represents a color in the RGBA color space. This representation is designed
for simplicity of conversion to/from color representations in various
languages over compactness. For example, the fields of this representation
can be trivially provided to the constructor of java.awt.Color in Java; it
can also be trivially provided to UIColor's +colorWithRed:green:blue:alpha
method in iOS; and, with just a little work, it can be easily formatted into
a CSS rgba() string in JavaScript.
This reference page doesn't carry information about the absolute color
space
that should be used to interpret the RGB value (e.g. sRGB, Adobe RGB,
DCI-P3, BT.2020, etc.). By default, applications should assume the sRGB color
space.
When color equality needs to be decided, implementations, unless
documented otherwise, treat two colors as equal if all their red,
green, blue, and alpha values each differ by at most 1e-5.
Example (Java):
import com.google.type.Color;
// ...
public static java.awt.Color fromProto(Color protocolor) {
float alpha = protocolor.hasAlpha()
? protocolor.getAlpha().getValue()
: 1.0;
return new java.awt.Color(
protocolor.getRed(),
protocolor.getGreen(),
protocolor.getBlue(),
alpha);
}
public static Color toProto(java.awt.Color color) {
float red = (float) color.getRed();
float green = (float) color.getGreen();
float blue = (float) color.getBlue();
float denominator = 255.0;
Color.Builder resultBuilder =
Color
.newBuilder()
.setRed(red / denominator)
.setGreen(green / denominator)
.setBlue(blue / denominator);
int alpha = color.getAlpha();
if (alpha != 255) {
result.setAlpha(
FloatValue
.newBuilder()
.setValue(((float) alpha) / denominator)
.build());
}
return resultBuilder.build();
}
// ...
This means that a value of 1.0 corresponds to a solid color, whereas
a value of 0.0 corresponds to a completely transparent color. This
uses a wrapper message rather than a simple float scalar so that it is
possible to distinguish between a default value and the value being unset.
If omitted, this color object is rendered as a solid color
(as if the alpha value had been explicitly given a value of 1.0).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[[["This page details the `Color` class, which represents a color in the RGBA color space and is part of the `Google.Type` namespace within the `Google.Api.CommonProtos.dll` assembly."],["The `Color` class is designed for easy conversion to and from color representations in various languages and includes fields for red, green, blue, and alpha components, all within the \\[0, 1] range, or in the case of the alpha, omitted for a solid color."],["The `Color` class has methods and properties for manipulation, such as `Clone()`, `Equals()`, and `MergeFrom()`, along with properties like `Red`, `Green`, `Blue`, and `Alpha` to access the color components."],["The documentation provides examples in Java, iOS/Obj-C, and JavaScript for converting to and from their respective color representations, with a default sRGB color space assumed if not specified."],["There are multiple versions of this class available, with the latest being version 2.15.0, and the class inherits from `object` and implements interfaces such as `IMessage`, `IEquatable`, `IDeepCloneable`, and `IBufferMessage`."]]],[]]