Color 結構
定義
表示 ARGB (Alpha、紅、綠、藍) 色彩。Represents an ARGB (alpha, red, green, blue) color.
public value class Color : IEquatable<System::Drawing::Color>
[System.ComponentModel.TypeConverter(typeof(System.Drawing.ColorConverter))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Color : IEquatable<System.Drawing.Color>
type Color = struct
Public Structure Color
Implements IEquatable(Of Color)
- 繼承
- 屬性
- 實作
範例
下列程式碼範例示範 Color 和 Implicit 成員的 A、R、G 和 B 屬性。The following code example demonstrates the A, R, G, and B properties of a Color, and the Implicit member.
這個範例是設計來與 Windows Form 搭配使用。This example is designed to be used with a Windows Form. 將程式碼貼入表單,並從表單的 Paint 事件處理方法呼叫 ShowPropertiesOfSlateBlue
方法,傳遞 e
作為 PaintEventArgs。Paste the code into the form and call the ShowPropertiesOfSlateBlue
method from the form's Paint event-handling method, passing e
as PaintEventArgs.
void ShowPropertiesOfSlateBlue( PaintEventArgs^ e )
{
Color slateBlue = Color::FromName( "SlateBlue" );
Byte g = slateBlue.G;
Byte b = slateBlue.B;
Byte r = slateBlue.R;
Byte a = slateBlue.A;
array<Object^>^temp0 = {a,r,g,b};
String^ text = String::Format( "Slate Blue has these ARGB values: Alpha:{0}, "
"red:{1}, green: {2}, blue {3}", temp0 );
e->Graphics->DrawString( text, gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), gcnew SolidBrush( slateBlue ), RectangleF(PointF(0.0F,0.0F),this->Size) );
}
private void ShowPropertiesOfSlateBlue(PaintEventArgs e)
{
Color slateBlue = Color.FromName("SlateBlue");
byte g = slateBlue.G;
byte b = slateBlue.B;
byte r = slateBlue.R;
byte a = slateBlue.A;
string text = String.Format("Slate Blue has these ARGB values: Alpha:{0}, " +
"red:{1}, green: {2}, blue {3}", new object[]{a, r, g, b});
e.Graphics.DrawString(text,
new Font(this.Font, FontStyle.Italic),
new SolidBrush(slateBlue),
new RectangleF(new PointF(0.0F, 0.0F), this.Size));
}
Private Sub ShowPropertiesOfSlateBlue(ByVal e As PaintEventArgs)
Dim slateBlue As Color = Color.FromName("SlateBlue")
Dim g As Byte = slateBlue.G
Dim b As Byte = slateBlue.B
Dim r As Byte = slateBlue.R
Dim a As Byte = slateBlue.A
Dim text As String = _
String.Format("Slate Blue has these ARGB values: Alpha:{0}, " _
& "red:{1}, green: {2}, blue {3}", New Object() {a, r, g, b})
e.Graphics.DrawString(text, New Font(Me.Font, FontStyle.Italic), _
New SolidBrush(slateBlue), _
New RectangleF(New PointF(0.0F, 0.0F), _
Size.op_Implicit(Me.Size)))
End Sub
備註
命名的色彩會使用 Color 結構的屬性來表示。Named colors are represented by using the properties of the Color structure. 如需這些色彩的詳細資訊,請參閱依名稱的色彩。For more information about these colors, see Colors by Name.
每個圖元的色彩都會以32位數位表示:8位,分別用於 Alpha、紅色、綠色和藍色(ARGB)。The color of each pixel is represented as a 32-bit number: 8 bits each for alpha, red, green, and blue (ARGB). 四個元件中的每個都是從0到255的數位,0代表沒有濃度,而255代表完整的濃度。Each of the four components is a number from 0 through 255, with 0 representing no intensity and 255 representing full intensity. Alpha 元件會指定色彩的透明度:0是完全透明的,而255則完全不透明。The alpha component specifies the transparency of the color: 0 is fully transparent, and 255 is fully opaque. 若要判斷色彩的 Alpha、紅色、綠色或藍色元件,請分別使用 [A]、[R]、[G] 或 [B] 屬性。To determine the alpha, red, green, or blue component of a color, use the A, R, G, or B property, respectively. 您可以使用其中一個 FromArgb 方法來建立自訂色彩。You can create a custom color by using one of the FromArgb methods.
欄位
Empty |
表示為 |
屬性
A |
取得這個 Color 結構的 Alpha 元件值。Gets the alpha component value of this Color structure. |
AliceBlue |
取得系統定義的色彩,此色彩具有 |
AntiqueWhite |
取得系統定義的色彩,此色彩具有 |
Aqua |
取得系統定義的色彩,此色彩具有 |
Aquamarine |
取得系統定義的色彩,此色彩具有 |
Azure |
取得系統定義的色彩,此色彩具有 |
B |
取得這個 Color 結構的藍色元件值。Gets the blue component value of this Color structure. |
Beige |
取得系統定義的色彩,此色彩具有 |
Bisque |
取得系統定義的色彩,此色彩具有 |
Black |
取得系統定義的色彩,此色彩具有 |
BlanchedAlmond |
取得系統定義的色彩,此色彩具有 |
Blue |
取得系統定義的色彩,此色彩具有 |
BlueViolet |
取得系統定義的色彩,此色彩具有 |
Brown |
取得系統定義的色彩,此色彩具有 |
BurlyWood |
取得系統定義的色彩,此色彩具有 |
CadetBlue |
取得系統定義的色彩,此色彩具有 |
Chartreuse |
取得系統定義的色彩,此色彩具有 |
Chocolate |
取得系統定義的色彩,此色彩具有 |
Coral |
取得系統定義的色彩,此色彩具有 |
CornflowerBlue |
取得系統定義的色彩,此色彩具有 |
Cornsilk |
取得系統定義的色彩,此色彩具有 |
Crimson |
取得系統定義的色彩,此色彩具有 |
Cyan |
取得系統定義的色彩,此色彩具有 |
DarkBlue |
取得系統定義的色彩,此色彩具有 |
DarkCyan |
取得系統定義的色彩,此色彩具有 |
DarkGoldenrod |
取得系統定義的色彩,此色彩具有 |
DarkGray |
取得系統定義的色彩,此色彩具有 |
DarkGreen |
取得系統定義的色彩,此色彩具有 |
DarkKhaki |
取得系統定義的色彩,此色彩具有 |
DarkMagenta |
取得系統定義的色彩,此色彩具有 |
DarkOliveGreen |
取得系統定義的色彩,此色彩具有 |
DarkOrange |
取得系統定義的色彩,此色彩具有 |
DarkOrchid |
取得系統定義的色彩,此色彩具有 |
DarkRed |
取得系統定義的色彩,此色彩具有 |
DarkSalmon |
取得系統定義的色彩,此色彩具有 |
DarkSeaGreen |
取得具有 |
DarkSlateBlue |
取得系統定義的色彩,此色彩具有 |
DarkSlateGray |
取得系統定義的色彩,此色彩具有 |
DarkTurquoise |
取得系統定義的色彩,此色彩具有 |
DarkViolet |
取得系統定義的色彩,此色彩具有 |
DeepPink |
取得系統定義的色彩,此色彩具有 |
DeepSkyBlue |
取得系統定義的色彩,此色彩具有 |
DimGray |
取得系統定義的色彩,此色彩具有 |
DodgerBlue |
取得系統定義的色彩,此色彩具有 |
Firebrick |
取得系統定義的色彩,此色彩具有 |
FloralWhite |
取得系統定義的色彩,此色彩具有 |
ForestGreen |
取得系統定義的色彩,此色彩具有 |
Fuchsia |
取得系統定義的色彩,此色彩具有 |
G |
取得這個 Color 結構的綠色元件值。Gets the green component value of this Color structure. |
Gainsboro |
取得系統定義的色彩,此色彩具有 |
GhostWhite |
取得系統定義的色彩,此色彩具有 |
Gold |
取得系統定義的色彩,此色彩具有 |
Goldenrod |
取得系統定義的色彩,此色彩具有 |
Gray |
取得系統定義的色彩,此色彩具有 |
Green |
取得系統定義的色彩,此色彩具有 |
GreenYellow |
取得系統定義的色彩,此色彩具有 |
Honeydew |
取得系統定義的色彩,此色彩具有 |
HotPink |
取得系統定義的色彩,此色彩具有 |
IndianRed |
取得系統定義的色彩,此色彩具有 |
Indigo |
取得系統定義的色彩,此色彩具有 |
IsEmpty |
指定這個 Color 結構是否未初始化。Specifies whether this Color structure is uninitialized. |
IsKnownColor |
取得值,指出這個 Color 結構是否為預先定義的色彩。Gets a value indicating whether this Color structure is a predefined color. 預先定義的色彩是由 KnownColor 列舉型別的項目所表示。Predefined colors are represented by the elements of the KnownColor enumeration. |
IsNamedColor |
取得值,指出這個 Color 結構是否為命名色彩,或是 KnownColor 列舉型別的成員。Gets a value indicating whether this Color structure is a named color or a member of the KnownColor enumeration. |
IsSystemColor |
取得值,指出這個 Color 結構是否為系統色彩。Gets a value indicating whether this Color structure is a system color. 系統色彩是用於 Windows 顯示項目的色彩。A system color is a color that is used in a Windows display element. 系統色彩是由 KnownColor 列舉型別的元素所表示。System colors are represented by elements of the KnownColor enumeration. |
Ivory |
取得系統定義的色彩,此色彩具有 |
Khaki |
取得系統定義的色彩,此色彩具有 |
Lavender |
取得系統定義的色彩,此色彩具有 |
LavenderBlush |
取得系統定義的色彩,此色彩具有 |
LawnGreen |
取得系統定義的色彩,此色彩具有 |
LemonChiffon |
取得系統定義的色彩,此色彩具有 |
LightBlue |
取得系統定義的色彩,此色彩具有 |
LightCoral |
取得系統定義的色彩,此色彩具有 |
LightCyan |
取得系統定義的色彩,此色彩具有 |
LightGoldenrodYellow |
取得系統定義的色彩,此色彩具有 |
LightGray |
取得系統定義的色彩,此色彩具有 |
LightGreen |
取得系統定義的色彩,此色彩具有 |
LightPink |
取得系統定義的色彩,此色彩具有 |
LightSalmon |
取得系統定義的色彩,此色彩具有 |
LightSeaGreen |
取得系統定義的色彩,此色彩具有 |
LightSkyBlue |
取得系統定義的色彩,此色彩具有 |
LightSlateGray |
取得系統定義的色彩,此色彩具有 |
LightSteelBlue |
取得系統定義的色彩,此色彩具有 |
LightYellow |
取得系統定義的色彩,此色彩具有 |
Lime |
取得系統定義的色彩,此色彩具有 |
LimeGreen |
取得系統定義的色彩,此色彩具有 |
Linen |
取得系統定義的色彩,此色彩具有 |
Magenta |
取得系統定義的色彩,此色彩具有 |
Maroon |
取得系統定義的色彩,此色彩具有 |
MediumAquamarine |
取得系統定義的色彩,此色彩具有 |
MediumBlue |
取得系統定義的色彩,此色彩具有 |
MediumOrchid |
取得系統定義的色彩,此色彩具有 |
MediumPurple |
取得系統定義的色彩,此色彩具有 |
MediumSeaGreen |
取得系統定義的色彩,此色彩具有 |
MediumSlateBlue |
取得系統定義的色彩,此色彩具有 |
MediumSpringGreen |
取得系統定義的色彩,此色彩具有 |
MediumTurquoise |
取得系統定義的色彩,此色彩具有 |
MediumVioletRed |
取得系統定義的色彩,此色彩具有 |
MidnightBlue |
取得系統定義的色彩,此色彩具有 |
MintCream |
取得系統定義的色彩,此色彩具有 |
MistyRose |
取得系統定義的色彩,此色彩具有 |
Moccasin |
取得系統定義的色彩,此色彩具有 |
Name | |
NavajoWhite |
取得系統定義的色彩,此色彩具有 |
Navy |
取得系統定義的色彩,此色彩具有 |
OldLace |
取得系統定義的色彩,此色彩具有 |
Olive |
取得系統定義的色彩,此色彩具有 |
OliveDrab |
取得系統定義的色彩,此色彩具有 |
Orange |
取得系統定義的色彩,此色彩具有 |
OrangeRed |
取得系統定義的色彩,此色彩具有 |
Orchid |
取得系統定義的色彩,此色彩具有 |
PaleGoldenrod |
取得系統定義的色彩,此色彩具有 |
PaleGreen |
取得系統定義的色彩,此色彩具有 |
PaleTurquoise |
取得系統定義的色彩,此色彩具有 |
PaleVioletRed |
取得系統定義的色彩,此色彩具有 |
PapayaWhip |
取得系統定義的色彩,此色彩具有 |
PeachPuff |
取得系統定義的色彩,此色彩具有 |
Peru |
取得系統定義的色彩,此色彩具有 |
Pink |
取得系統定義的色彩,此色彩具有 |
Plum |
取得系統定義的色彩,此色彩具有 |
PowderBlue |
取得系統定義的色彩,此色彩具有 |
Purple |
取得系統定義的色彩,此色彩具有 |
R |
取得這個 Color 結構的紅色元件值。Gets the red component value of this Color structure. |
Red |
取得系統定義的色彩,此色彩具有 |
RosyBrown |
取得系統定義的色彩,此色彩具有 |
RoyalBlue |
取得系統定義的色彩,此色彩具有 |
SaddleBrown |
取得系統定義的色彩,此色彩具有 |
Salmon |
取得系統定義的色彩,此色彩具有 |
SandyBrown |
取得系統定義的色彩,此色彩具有 |
SeaGreen |
取得系統定義的色彩,此色彩具有 |
SeaShell |
取得系統定義的色彩,此色彩具有 |
Sienna |
取得系統定義的色彩,此色彩具有 |
Silver |
取得系統定義的色彩,此色彩具有 |
SkyBlue |
取得系統定義的色彩,此色彩具有 |
SlateBlue |
取得系統定義的色彩,此色彩具有 |
SlateGray |
取得系統定義的色彩,此色彩具有 |
Snow |
取得系統定義的色彩,此色彩具有 |
SpringGreen |
取得系統定義的色彩,此色彩具有 |
SteelBlue |
取得系統定義的色彩,此色彩具有 |
Tan |
取得系統定義的色彩,此色彩具有 |
Teal |
取得系統定義的色彩,此色彩具有 |
Thistle |
取得系統定義的色彩,此色彩具有 |
Tomato |
取得系統定義的色彩,此色彩具有 |
Transparent |
取得系統定義的色彩。Gets a system-defined color. |
Turquoise |
取得系統定義的色彩,此色彩具有 |
Violet |
取得系統定義的色彩,此色彩具有 |
Wheat |
取得系統定義的色彩,此色彩具有 |
White |
取得系統定義的色彩,此色彩具有 |
WhiteSmoke |
取得系統定義的色彩,此色彩具有 |
Yellow |
取得系統定義的色彩,此色彩具有 |
YellowGreen |
取得系統定義的色彩,此色彩具有 |
方法
Equals(Color) | |
Equals(Object) |
測試指定的物件是否為 Color 結構,並且和這個 Color 結構相等。Tests whether the specified object is a Color structure and is equivalent to this Color structure. |
FromArgb(Int32) |
從 32 位元的 ARGB 值建立 Color 結構。Creates a Color structure from a 32-bit ARGB value. |
FromArgb(Int32, Color) |
從指定的 Color 結構 (但是使用新指定的 Alpha 值) 建立 Color 結構。Creates a Color structure from the specified Color structure, but with the new specified alpha value. 雖然這個方法允許為 Alpha 值傳遞 32 位元值,但是該值是限制為 8 位元。Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits. |
FromArgb(Int32, Int32, Int32) |
從指定的 8 位元色彩值 (紅、綠和藍) 建立 Color 結構。Creates a Color structure from the specified 8-bit color values (red, green, and blue). Alpha 值隱含為 255 (完全不透明)。The alpha value is implicitly 255 (fully opaque). 雖然這個方法允許為每個色彩元件傳遞 32 位元值,但是每個元件的值是限制為 8 位元。Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits. |
FromArgb(Int32, Int32, Int32, Int32) |
從四個 ARGB 元件 (Alpha、紅、綠和藍) 值建立 Color 結構。Creates a Color structure from the four ARGB component (alpha, red, green, and blue) values. 雖然這個方法允許為每個元件傳遞 32 位元值,但是每個元件的值是限制為 8 位元。Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits. |
FromKnownColor(KnownColor) |
從指定的預先定義色彩建立 Color 結構。Creates a Color structure from the specified predefined color. |
FromName(String) |
從指定的預先定義色彩名稱建立 Color 結構。Creates a Color structure from the specified name of a predefined color. |
GetBrightness() |
取得這個 Color 結構的色相-彩度-亮度 (HSL) 的亮度值。Gets the hue-saturation-lightness (HSL) lightness value for this Color structure. |
GetHashCode() |
傳回這個 Color 結構的雜湊程式碼。Returns a hash code for this Color structure. |
GetHue() |
取得這個 Color 結構的色相-彩度-亮度 (HSL) 的色相值,單位為度。Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this Color structure. |
GetSaturation() |
取得這個 Color 結構的色相-彩度-亮度 (HSL) 的彩度值。Gets the hue-saturation-lightness (HSL) saturation value for this Color structure. |
ToArgb() |
取得這個 Color 結構的 32 位元 ARGB 值。Gets the 32-bit ARGB value of this Color structure. |
ToKnownColor() |
取得這個 KnownColor 結構的 Color 值。Gets the KnownColor value of this Color structure. |
ToString() |
將這個 Color 結構轉換為人們可讀取的 (Human-Readable) 字串。Converts this Color structure to a human-readable string. |
運算子
Equality(Color, Color) |
測試兩個指定的 Color 結構是否相等。Tests whether two specified Color structures are equivalent. |
Inequality(Color, Color) |
測試兩個指定的 Color 結構是否不同。Tests whether two specified Color structures are different. |