Color.GetHue Método

Definição

Obtém o valor de matiz HSL (matiz-saturação-luminosidade), em graus, desta estrutura Color.

public:
 float GetHue();
public float GetHue ();
member this.GetHue : unit -> single
Public Function GetHue () As Single

Retornos

O matiz, em graus, desta Color. O matiz é medido em graus, variando de 0,0 a 360,0, no espaço de cores HSL.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:

  • Cria uma instância de uma Color estrutura, redShade, a ser usada para comparações.

  • Itera pelos elementos de KnownColor enumeração para localizar todas as cores conhecidas que têm o mesmo matiz que redShade. As iterações são encerradas quando 15 correspondências são encontradas ou o valor do contador de loop é maior que o último KnownColor elemento.

  • Durante cada iteração, salva o KnownColor elemento – se ele corresponder aos critérios – em uma matriz.

  • Usa um pincel para pintar retângulos.

O primeiro retângulo é pintado com a cor representada por redShade. Cada um dos outros retângulos é pintado um KnownColor que corresponde à tonalidade do redShade.

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.
   array<KnownColor>^colorMatches = gcnew array<KnownColor>(15);

   // Number of matches found.
   int count = 0;

   // Iterate through the KnownColor enums until 15 matches are found.
   for ( KnownColor enumValue = (KnownColor)0; enumValue <= KnownColor::YellowGreen && count < 15; enumValue = enumValue + (KnownColor)1 )
   {
      someColor = Color::FromKnownColor( enumValue );
      if ( someColor.GetHue() == redShade.GetHue() )
               colorMatches[ count++ ] = enumValue;
   }

   // Display the redShade color and its argb value.
   SolidBrush^ myBrush1 = gcnew SolidBrush( redShade );
   System::Drawing::Font^ myFont = gcnew System::Drawing::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, (float)x + 120, (float)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, (float)x + 120, (float)y );
   }
}
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);
    }
}
Public Sub GetHueExample(ByVal e As PaintEventArgs)
    Dim g As Graphics = e.Graphics

    ' Color structures. One is used for temporary storage. The other
    ' is a constant used for comparisons.
    Dim someColor As Color = Color.FromArgb(0)
    Dim redShade As Color = Color.FromArgb(255, 200, 0, 100)

    ' Array for KnownColor values that match the hue of redShade
    ' color.
    Dim colorMatches(15) As KnownColor

    ' Number of matches found.
    Dim count As Integer = 0

    ' Iterate through the KnownColor enums until 15 matches are found.
    Dim enumValue As KnownColor
    For enumValue = 0 To KnownColor.YellowGreen
        someColor = Color.FromKnownColor(enumValue)
        If (someColor.GetHue()) = (redShade.GetHue()) Then
            colorMatches(count) = enumValue
            count += 1
            If count > 15 Then
                Exit For
            End If
        End If
    Next enumValue

    ' Display the redShade color and its argb value.
    Dim myBrush1 As New SolidBrush(redShade)
    Dim myFont As New Font("Arial", 12)
    Dim x As Integer = 20
    Dim y As Integer = 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.
    Dim i As Integer
    For i = 0 To count - 1
        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)
    Next i
End Sub

Aplica-se a