Color.GetBrightness メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Color.GetBrightness メソッドの意味・解説 

Color.GetBrightness メソッド

この Color 構造体の、HSB (hue-saturation-brightness) の明るさの値を取得します

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

public float GetBrightness ()
public:
float GetBrightness ()
public float GetBrightness ()
public function GetBrightness () : float

戻り値
この Color明るさ明るさ範囲は 0.0 から 1.0 で、0.0 は黒を、1.0 は白を表します

使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

最初四角形は、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Color.GetBrightness メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Color.GetBrightness メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS