Color 结构

定义

从 alpha、红色、绿色和蓝色通道角度描述一种颜色。Describes a color in terms of alpha, red, green, and blue channels.

public value class Color : IEquatable<System::Windows::Media::Color>, IFormattable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Media.ColorConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public struct Color : IEquatable<System.Windows.Media.Color>, IFormattable
type Color = struct
    interface IFormattable
Public Structure Color
Implements IEquatable(Of Color), IFormattable
继承
属性
实现

示例

此示例演示如何使用 sRGB、ScRGB 和颜色配置文件值创建蓝色。This example shows how to use sRGB, ScRGB, and color profile values to create the color blue.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<StackPanel Margin="20">
  
  <!-- This rectangle fill uses a Color with ScRGB values to
       create a completely opaque blue. -->
  <Rectangle Width="50" Height="50"  Margin="10">
     <Rectangle.Fill>
       <SolidColorBrush>
         <SolidColorBrush.Color>

           <!-- Describes the brush's color using
                ScRGB values. Each value has a range of 0-1.  -->
           <Color ScA="1.0" ScR="0.0" ScG="0.0" ScB="1.0" />
        </SolidColorBrush.Color>
      </SolidColorBrush>
    </Rectangle.Fill>
  </Rectangle>

  <!-- This rectangle fill uses a Color with sRGB values to
       create a completely opaque blue. -->
  <Rectangle Width="50" Height="50"  Margin="10">
     <Rectangle.Fill>
       <SolidColorBrush>
         <SolidColorBrush.Color>

           <!-- Describes the brush's color using
                sRGB values. Each value is a byte with range of 0-255.  -->
           <Color A="255" R="0" G="0" B="255" />
        </SolidColorBrush.Color>
      </SolidColorBrush>
    </Rectangle.Fill>
  </Rectangle>

  <!-- This rectangle fill uses the sRGB color profile and values to
       create a complete opaque blue. -->
  <Rectangle Width="50" Height="50"  Margin="10">
    <Rectangle.Fill>
      <SolidColorBrush Color="ContextColor 
       file://C:/WINDOWS/system32/spool/drivers/color/sRGB%20Color%20Space%20Profile.icm
       1.0,0.0,0.0,1.0"/>
    </Rectangle.Fill>
  </Rectangle>

</StackPanel>
</Page>

注解

XAML 属性用法XAML Attribute Usage

<object property="predefinedColor"/>  
- or -  
<object property="#rgb"/>  
- or -  
<object property="#argb"/>  
- or -  
<object property="#rrggbb"/>  
- or -  
<object property="#aarrggbb"/>  
- or -  
<object property="sc# scA,scR,scG,scB"/>  
- or -  
<object property="ContextColor profileUri alphaValue,colorValue"/>  
  

XAML 值XAML Values

predefinedColorpredefinedColor
Colors类预定义的颜色之一。One of the colors predefined by the Colors class.

rgbrgb
三位十六进制数。A three-digit hexadecimal number. 第一个数字指定颜色的R值, 第二个数字G指定值, 第三B个数字指定值。The first digit specifies the color's R value, the second digit specifies the G value, and the third digit specifies the B value. 例如 00FFor example, 00F.

argbargb
四位十六进制数。A four-digit hexadecimal number. 第一个数字A指定颜色的值, 第二个数字指定其R值, 下一个数字G指定值, 最后一个数字指定其B值。The first digit specifies the color's A value, the second digit specifies its R value, the next digit specifies the G value, and the final digit specifies its B value. 例如 F00FFor example, F00F.

rrggbbrrggbb
六位十六进制数。A six-digit hexadecimal number. 前两位数字指定颜色的R值, 接下来的两个数字指定其G值, 最后两B个数字指定其值。The first two digits specify the color's R value, the next two specify its G value, and the final two specify its B value. 例如 0000FFFor example, 0000FF.

aarrggbbaarrggbb
8位十六进制数。An eight-digit hexadecimal number. 前两位数字指定颜色A的值, 接下来的两个值指定其R值, 接下来G的两个数字指定其值, 最后B两个数字指定其值。The first two digits specify the color's A value, the next two specify its R value, the next two specify its G value, and the final two specify its B value. 例如 FF0000FFFor example, FF0000FF.

scAscA
System.Single

颜色的ScA值。The color's ScA value.

scRscR
System.Single

颜色的ScR值。The color's ScR value.

scGscG
System.Single

颜色的ScG值。The color's ScG value.

scBscB
System.Single

颜色的ScB值。The color's ScB value.

profileUriprofileUri
System.Uri

国际色彩联合会 (ICC)International Color Consortium (ICC)图像颜色管理 (ICM)Image Color Management (ICM)颜色配置文件。The 国际色彩联合会 (ICC)International Color Consortium (ICC) or 图像颜色管理 (ICM)Image Color Management (ICM) color profile.

alphaValuealphaValue
System.Single

Alpha 通道颜色值。The alpha channel color value. 值范围为0.0 到1.0。The value range is 0.0 to 1.0.

colorValuecolorValue
System.Single

以逗号分隔的列表, 其中包含三到八个值, 它们表示颜色配置文件的颜色通道。A comma-delimited list of three to eight values that represent the color channels of the color profile. 值范围为0.0 到1.0。The value range is 0.0 to 1.0.

属性

A

获取或设置颜色的 sRGB alpha 通道值。Gets or sets the sRGB alpha channel value of the color.

B

获取或设置颜色的 sRGB 蓝色通道值。Gets or sets the sRGB blue channel value of the color.

ColorContext

获取颜色的 国际色彩联合会 (ICC)International Color Consortium (ICC)图像颜色管理 (ICM)Image Color Management (ICM) 颜色配置文件。Gets the 国际色彩联合会 (ICC)International Color Consortium (ICC) or 图像颜色管理 (ICM)Image Color Management (ICM) color profile of the color.

G

获取或设置颜色的 sRGB 绿色通道值。Gets or sets the sRGB green channel value of the color.

R

获取或设置颜色的 sRGB 红色通道值。Gets or sets the sRGB red channel value of the color.

ScA

获取或设置颜色的 ScRGB alpha 通道值。Gets or sets the ScRGB alpha channel value of the color.

ScB

获取或设置颜色的 ScRGB 蓝色通道值。Gets or sets the ScRGB blue channel value of the color.

ScG

获取或设置颜色的 ScRGB 绿色通道值。Gets or sets the ScRGB green channel value of the color.

ScR

获取或设置颜色的 ScRGB 红色通道值。Gets or sets the ScRGB red channel value of the color.

方法

Add(Color, Color)

将两个 Color 结构相加。Adds two Color structures.

AreClose(Color, Color)

比较两个 Color 结构是否模糊相等。Compares two Color structures for fuzzy equality.

Clamp()

如果颜色的 ScRGB 通道不在 0 到 1 的范围内,请将它们设置在此范围内。Sets the ScRGB channels of the color to within the gamut of 0 to 1, if they are outside that range.

Equals(Color)

测试指定的对象是否为 Color 结构并与当前颜色完全相同。Tests whether the specified Color structure is identical to this color.

Equals(Color, Color)

测试两个 Color 结构是否相同。Tests whether two Color structures are identical.

Equals(Object)

测试指定的对象是否为 Color 结构并等同于当前颜色。Tests whether the specified object is a Color structure and is equivalent to this color.

FromArgb(Byte, Byte, Byte, Byte)

使用指定的 sRGB Alpha 通道和颜色通道值创建一个新的 Color 结构。Creates a new Color structure by using the specified sRGB alpha channel and color channel values.

FromAValues(Single, Single[], Uri)

使用指定的 Alpha 通道、颜色通道值和颜色配置文件创建一个新的 Color 结构。Creates a new Color structure by using the specified alpha channel, color channel values, and color profile.

FromRgb(Byte, Byte, Byte)

使用指定的 sRGB 颜色通道值创建一个新的 Color 结构。Creates a new Color structure by using the specified sRGB color channel values.

FromScRgb(Single, Single, Single, Single)

使用指定的 ScRGB Alpha 通道和颜色通道值创建一个新的 Color 结构。Creates a new Color structure by using the specified ScRGB alpha channel and color channel values.

FromValues(Single[], Uri)

使用指定的颜色通道值和颜色配置文件创建一个新的 Color 结构。Creates a new Color structure by using the specified color channel values and color profile.

GetHashCode()

获取此 Color 结构的哈希代码。Gets a hash code for this Color structure.

GetNativeColorValues()

获取颜色的颜色通道值。Gets the color channel values of the color.

Multiply(Color, Single)

将指定的 Color 结构的 Alpha、红色、蓝色和绿色通道与指定值相乘。Multiplies the alpha, red, blue, and green channels of the specified Color structure by the specified value.

Subtract(Color, Color)

从一个 Color 结构中减去一个 Color 结构。Subtracts a Color structure from a Color structure.

ToString()

使用 sRGB 通道创建颜色的字符串表示形式。Creates a string representation of the color using the sRGB channels.

ToString(IFormatProvider)

使用 sRGB 通道和指定的格式提供程序创建颜色的字符串表示形式。Creates a string representation of the color by using the sRGB channels and the specified format provider.

操作员

Addition(Color, Color)

将两个 Color 结构相加。Adds two Color structures.

Equality(Color, Color)

测试两个 Color 结构是否相同。Tests whether two Color structures are identical.

Inequality(Color, Color)

测试两个 Color 结构是否不同。Tests whether two Color structures are not identical.

Multiply(Color, Single)

将指定的 Color 结构的 Alpha、红色、蓝色和绿色通道与指定值相乘。Multiplies the alpha, red, blue, and green channels of the specified Color structure by the specified value.

Subtraction(Color, Color)

从一个 Color 结构中减去一个 Color 结构。Subtracts a Color structure from a Color structure.

显式界面实现

IFormattable.ToString(String, IFormatProvider)

使用指定的格式格式化当前实例的值。Formats the value of the current instance using the specified format.

适用于