次の方法で共有


Color.FromArgb メソッド (Int32, Int32, Int32)

指定の 8 ビット カラー値 (赤、緑、青) から Color 構造体を作成します。アルファ値は暗黙的に 255 (完全不透明) になります。このメソッドでは各カラー コンポーネントの 32 ビット値を渡すことができますが、各カラー コンポーネントの値は 8 ビットに限定されます。

Overloads Public Shared Function FromArgb( _
   ByVal red As Integer, _   ByVal green As Integer, _   ByVal blue As Integer _) As Color
[C#]
public static Color FromArgb(intred,intgreen,intblue);
[C++]
public: static Color FromArgb(intred,intgreen,intblue);
[JScript]
public static function FromArgb(
   red : int,green : int,blue : int) : Color;

パラメータ

  • red
    新しい Color 構造体の赤のコンポーネントの値。有効な値は 0 から 255 です。
  • green
    新しい Color 構造体の緑のコンポーネントの値。有効な値は 0 から 255 です。
  • blue
    新しい Color 構造体の青のコンポーネントの値。有効な値は 0 から 255 です。

戻り値

このメソッドが作成する Color 構造体。

使用例

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

  • 3 つのカラー コンポーネントの値 (赤、緑、青) から Color 構造体を作成します。3 つの Color 構造体は、それぞれ原色で作成されます。
  • アルファ値の範囲を反復処理して、色のアルファ値を変更します。
  • 各反復処理中、ブラシの色を変更した色に設定し、三角形をその色で塗りつぶします。
  • 各原色に対してステップ 2 とステップ 3 の操作を繰り返します。

[Visual Basic, C#] アルファ値は完全には不透明にはならず、三角形が重複するため、色の組み合わせ効果を得ることができます。

 
Public Sub FromArgb_2_4(e As PaintEventArgs)
Dim g As Graphics = e.Graphics
' Opaque colors (alpha value defaults to 255 -- max value).
Dim red As Color = Color.FromArgb(255, 0, 0)
Dim green As Color = Color.FromArgb(0, 255, 0)
Dim blue As Color = Color.FromArgb(0, 0, 255)
' Solid brush initialized to red.
Dim myBrush As New SolidBrush(red)
Dim alpha As Integer
Dim x As Integer = 50 ' x coordinate of first red rectangle
Dim y As Integer = 50 ' y coordinate of first red rectangle
' Fill rectangles with red, varying the alpha value from 25 to 250.
For alpha = 25 To 250 Step 25
myBrush.Color = Color.FromArgb(alpha, red)
g.FillRectangle(myBrush, x, y, 50, 100)
g.FillRectangle(myBrush, x, y + 250, 50, 50)
x += 50
Next alpha
x = 50 ' x coordinate of first green rectangle
y += 50 ' y coordinate of first green rectangle
' Fill rectangles with green, varying alpha value from 25 to 250.
For alpha = 25 To 250 Step 25
myBrush.Color = Color.FromArgb(alpha, green)
g.FillRectangle(myBrush, x, y, 50, 150)
x += 50
Next alpha
x = 50 ' x coordinate of first blue rectangle
y += 100 ' y coordinate of first blue rectangle
' Fill rectangles with blue, varying alpha value from 25 to 250.
For alpha = 25 To 250 Step 25
myBrush.Color = Color.FromArgb(alpha, blue)
g.FillRectangle(myBrush, x, y, 50, 150)
x += 50
Next alpha
End Sub
        
[C#] 
public void FromArgb_2_4(PaintEventArgs e)
{
Graphics     g = e.Graphics;
// Opaque colors (alpha value defaults to 255 -- max value).
Color red = Color.FromArgb(255, 0, 0);
Color green = Color.FromArgb(0, 255, 0);
Color blue = Color.FromArgb(0, 0, 255);
// Solid brush initialized to red.
SolidBrush  myBrush = new SolidBrush(red);
int alpha;
int x = 50;         // x coordinate of first red rectangle
int y = 50;         // y coordinate of first red rectangle
// Fill rectangles with red, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, red);
g.FillRectangle(myBrush, x, y, 50, 100);
g.FillRectangle(myBrush, x, y + 250, 50, 50);
x += 50;
}
x = 50;             // x coordinate of first green rectangle
y += 50;            // y coordinate of first green rectangle
// Fill rectangles with green, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, green);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
x = 50;             // x coordinate of first blue rectangle
y += 100;           // y coordinate of first blue rectangle
// Fill rectangles with blue, varying the alpha value from 25 to 250.
for (alpha = 25; alpha <= 250; alpha += 25)
{
myBrush.Color = Color.FromArgb(alpha, blue);
g.FillRectangle(myBrush, x, y, 50, 150);
x += 50;
}
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Color 構造体 | Color メンバ | System.Drawing 名前空間 | Color.FromArgb オーバーロードの一覧