Description
The WithAlpha
method allows you to create a new Color
instance with a modified alpha (transparency) value, while keeping the red, green, and blue components unchanged. This method is useful when you need to adjust the transparency of a color without altering its hue or saturation.
Usage
To use the WithAlpha
method, call it on an existing Color
instance and pass a float
value representing the new alpha level. The alpha value should be between 0 (fully transparent) and 1 (fully opaque).
Example
Color originalColor = new Color(0.5f, 0.5f, 0.5f, 1.0f); // A gray color with full opacity
Color semiTransparentColor = originalColor.WithAlpha(0.5f); // The same gray color but with 50% transparency