Color.GetHue Yöntem

Tanım

Bu Color yapısı için ton doygunluk hafifliği (HSL) ton değerini derece olarak alır.

C#
public float GetHue ();

Döndürülenler

Bu Colorderece olarak ton. Ton, HSL renk alanında 0,0 ile 360,0 arasında derece cinsinden ölçülür.

Örnekler

Aşağıdaki kod örneği Windows Forms ile kullanılmak üzere tasarlanmıştır ve Paint olay işleyicisinin bir parametresi olan PaintEventArgsegerektirir. Kod aşağıdaki eylemleri gerçekleştirir:

  • Karşılaştırmalar için kullanılacak Color yapısının redShadebir örneğini oluşturur.

  • redShadeile aynı tona sahip tüm bilinen renkleri bulmak için KnownColor numaralandırma öğelerinde yinelenir. 15 eşleşme bulunduğunda veya döngü sayacının değeri son KnownColor öğesinden büyük olduğunda yinelemeler sonlandırılır.

  • Her yineleme sırasında, KnownColor öğesini (ölçütlerle eşleşiyorsa) bir diziye kaydeder.

  • Dikdörtgenleri boyamak için fırça kullanır.

İlk dikdörtgen, redShadeile temsil edilen renge boyanmış. Diğer dikdörtgenlerin her biri, redShadetonuyla eşleşen bir KnownColor boyanmış.

C#
public void GetHueExample(PaintEventArgs e)
{
    Graphics     g = e.Graphics;
             
    // Color structures. One is a variable used for temporary storage. The other
    // is a constant used for comparisons.
    Color   someColor = Color.FromArgb(0);
    Color   redShade = Color.FromArgb(255, 200, 0, 100);
             
    // Array to store KnownColor values that match the hue of the redShade
    // color.
    KnownColor[]  colorMatches = new KnownColor[15];

    // Number of matches found.
    int  count = 0;   
    
    // Iterate through the KnownColor enums until 15 matches are found.
    for (KnownColor enumValue = 0;
        enumValue <= KnownColor.YellowGreen && count < 15; enumValue++)
    {
        someColor = Color.FromKnownColor(enumValue);
        if (someColor.GetHue() == redShade.GetHue())
            colorMatches[count++] = enumValue;
    }
             
    // Display the redShade color and its argb value.
    SolidBrush  myBrush1 = new SolidBrush(redShade);
    Font        myFont = new Font("Arial", 12);
    int         x = 20;
    int         y = 20;
    someColor = redShade;
    g.FillRectangle(myBrush1, x, y, 100, 30);
    g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y);
             
    // Iterate through the matches that were found and display each color that
    // corresponds with the enum value in the array. also display the name of
    // the KnownColor.
    for (int i = 0; i < count; i++)
    {
        y += 40;
        someColor = Color.FromKnownColor(colorMatches[i]);
        myBrush1.Color = someColor;
        g.FillRectangle(myBrush1, x, y, 100, 30);
        g.DrawString(someColor.ToString(), myFont, Brushes.Black, x + 120, y);
    }
}

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1