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
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Media.ColorConverter))>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
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 Attribute UsageXAML 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
由類別預先定義的其中一種色彩 ColorsOne 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
八位數的十六進位數位。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.

渣 打 銀行scB
System.Single

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

profileUriprofileUri
System.Uri

國際色彩聯盟 (ICC) 或影像色彩管理 (ICM) 色設定檔。The International Color Consortium (ICC) or 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) 或影像色彩管理 (色彩的 ICM) 色彩設定檔。Gets the International Color Consortium (ICC) or 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.

適用於