Color Color Color Color Struct

定義

根據 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 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
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
八位數的十六進位數位。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 A A A

取得或設定色彩的 sRGB Alpha 色頻值。Gets or sets the sRGB alpha channel value of the color.

B B B B

取得或設定色彩的 sRGB 藍色色頻值。Gets or sets the sRGB blue channel value of the color.

ColorContext ColorContext ColorContext 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 G G G

取得或設定色彩的 sRGB 綠色色頻值。Gets or sets the sRGB green channel value of the color.

R R R R

取得或設定色彩的 sRGB 紅色色頻值。Gets or sets the sRGB red channel value of the color.

ScA ScA ScA ScA

取得或設定色彩的 ScRGB Alpha 色頻值。Gets or sets the ScRGB alpha channel value of the color.

ScB ScB ScB ScB

取得或設定色彩的 ScRGB 藍色色頻值。Gets or sets the ScRGB blue channel value of the color.

ScG ScG ScG ScG

取得或設定色彩的 ScRGB 綠色色頻值。Gets or sets the ScRGB green channel value of the color.

ScR ScR ScR ScR

取得或設定色彩的 ScRGB 紅色色頻值。Gets or sets the ScRGB red channel value of the color.

方法

Add(Color, Color) Add(Color, Color) Add(Color, Color) Add(Color, Color)

將兩個 Color 結構相加。Adds two Color structures.

AreClose(Color, Color) AreClose(Color, Color) AreClose(Color, Color) AreClose(Color, Color)

比較兩個 Color 結構是否接近相等。Compares two Color structures for fuzzy equality.

Clamp() Clamp() Clamp() 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(Object) Equals(Object) Equals(Object) Equals(Object)

測試指定的物件是否為 Color 結構且相當於這個色彩。Tests whether the specified object is a Color structure and is equivalent to this color.

Equals(Color) Equals(Color) Equals(Color) Equals(Color)

測試指定的 Color 結構是否和這個色彩相等。Tests whether the specified Color structure is identical to this color.

Equals(Color, Color) Equals(Color, Color) Equals(Color, Color) Equals(Color, Color)

測試兩個 Color 結構是否一致。Tests whether two Color structures are identical.

FromArgb(Byte, Byte, Byte, Byte) FromArgb(Byte, Byte, Byte, Byte) FromArgb(Byte, Byte, Byte, Byte) 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) FromAValues(Single, Single[], Uri) FromAValues(Single, Single[], Uri) 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) FromRgb(Byte, Byte, Byte) FromRgb(Byte, Byte, Byte) FromRgb(Byte, Byte, Byte)

使用指定的 sRGB 色彩和色板值建立新的 Color 結構。Creates a new Color structure by using the specified sRGB color channel values.

FromScRgb(Single, Single, Single, Single) FromScRgb(Single, Single, Single, Single) FromScRgb(Single, Single, Single, Single) 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) FromValues(Single[], Uri) FromValues(Single[], Uri) FromValues(Single[], Uri)

使用指定的色頻值和色彩設定檔建立新的 Color 結構。Creates a new Color structure by using the specified color channel values and color profile.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

取得這個 Color 結構的雜湊程式碼。Gets a hash code for this Color structure.

GetNativeColorValues() GetNativeColorValues() GetNativeColorValues() GetNativeColorValues()

取得色彩的色頻值。Gets the color channel values of the color.

Multiply(Color, Single) Multiply(Color, Single) Multiply(Color, Single) 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) Subtract(Color, Color) Subtract(Color, Color) Subtract(Color, Color)

Color 結構減去 Color 結構。Subtracts a Color structure from a Color structure.

ToString() ToString() ToString() ToString()

使用 sRGB 色板建立色彩的字串表示。Creates a string representation of the color using the sRGB channels.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

使用 sRGB 色頻和指定的格式提供者建立色彩的字串表示。Creates a string representation of the color by using the sRGB channels and the specified format provider.

運算子

Addition(Color, Color) Addition(Color, Color) Addition(Color, Color) Addition(Color, Color)

將兩個 Color 結構相加。Adds two Color structures.

Equality(Color, Color) Equality(Color, Color) Equality(Color, Color) Equality(Color, Color)

測試兩個 Color 結構是否一致。Tests whether two Color structures are identical.

Inequality(Color, Color) Inequality(Color, Color) Inequality(Color, Color) Inequality(Color, Color)

測試兩個 Color 結構是否不相等。Tests whether two Color structures are not identical.

Multiply(Color, Single) Multiply(Color, Single) Multiply(Color, Single) 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) Subtraction(Color, Color) Subtraction(Color, Color) Subtraction(Color, Color)

Color 結構減去 Color 結構。Subtracts a Color structure from a Color structure.

明確介面實作

IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider) IFormattable.ToString(String, IFormatProvider)

使用指定的格式,格式化目前執行個體的值。Formats the value of the current instance using the specified format.

適用於