다음을 통해 공유


Color.GetBrightness 메서드

Color 구조체의 HSB(Hue-Saturation-Brightness) 밝기 값을 가져옵니다.

네임스페이스: System.Drawing
어셈블리: System.Drawing(system.drawing.dll)

구문

‘선언
Public Function GetBrightness As Single
‘사용 방법
Dim instance As Color
Dim returnValue As Single

returnValue = instance.GetBrightness
public float GetBrightness ()
public:
float GetBrightness ()
public float GetBrightness ()
public function GetBrightness () : float

반환 값

Color의 밝기입니다. 밝기의 범위는 0.0부터 1.0까지이며, 여기서 0.0은 검정이며 1.0은 흰색입니다.

예제

다음 코드 예제는 Windows Forms에 적용되며, 여기에는 Paint 이벤트 처리기의 매개 변수인 PaintEventArgse가 필요합니다. 이 코드는 다음 작업을 수행합니다.

  • 비교에 사용될 Color 구조체, redShade의 인스턴스를 만듭니다.

  • 밝기가 redShade와 동일한 모든 이미 알려진 색을 찾기 위해 KnownColor 열거형 요소 전체를 반복합니다. 15개의 일치를 찾거나 루프 카운터가 마지막 KnownColor 요소보다 크면 반복이 종료됩니다.

  • 반복할 때마다 KnownColor 요소가 기준과 일치하면 이 요소를 배열에 저장합니다.

  • 네모를 그리는 데 브러시를 사용합니다.

첫 번째 네모는 redShade의 색으로 그려집니다. 각각의 다른 네모는 redShade의 밝기와 일치하는 KnownColor으로 그려집니다.

Public Sub KnownColorBrightnessExample2(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 to store KnownColor values that match the brightness of the
    ' 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.GetBrightness()) = (redShade.GetBrightness()) 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.
    ' 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
public void KnownColorBrightnessExample2(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 brightness 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.GetBrightness() == redShade.GetBrightness())
            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);
    }
}
void KnownColorBrightnessExample2( 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 brightness 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.GetBrightness() == redShade.GetBrightness() )
               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 KnownColorBrightnessExample2(PaintEventArgs e)
{
    Graphics g = e.get_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 brightness 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 = (KnownColor)0; 
        (enumValue.CompareTo(KnownColor.YellowGreen) <= 0) 
        && (count < 15); enumValue++) {

        someColor = Color.FromKnownColor(enumValue);
        if (someColor.GetBrightness() == redShade.GetBrightness()) {
            colorMatches.set_Item(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.get_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(
            (KnownColor)colorMatches.get_Item(i));
        myBrush1.set_Color(someColor);
        g.FillRectangle(myBrush1, x, y, 100, 30);
        g.DrawString(someColor.ToString(), myFont, Brushes.get_Black(), 
            x + 120, y);
    }
} //KnownColorBrightnessExample2

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Color 구조체
Color 멤버
System.Drawing 네임스페이스