32 ビットの ARGB 値から Color 構造体を作成します。
Overloads Public Shared Function FromArgb( _
ByVal argb As Integer _) As Color
[C#]
public static Color FromArgb(intargb);
[C++]
public: static Color FromArgb(intargb);
[JScript]
public static function FromArgb(
argb : int) : Color;
パラメータ
- argb
32 ビットの ARGB 値を指定する値。
戻り値
このメソッドが作成する Color 構造体。
解説
32 ビットの ARGB 値のバイト順は AARRGGBB です。AA で表している最上位バイト (MSB) はアルファ コンポーネントの値です。RR、GG、BB で表している 2 番目、3 番目、4 番目のバイトは、それぞれ赤、緑、青のカラー コンポーネントです。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- 色が異なる 3 つのブラシを作成します。ブラシの作成に使用する各 Color 構造体は、32 ビットの ARGB 値から作成されます。
- 架空の三角形を使用して 3 つの円の位置を指定します。
- 三角形の各頂点を中心とする 3 つの重なった円をそれぞれ異なるブラシで塗りつぶします。
Public Sub FromArgb_3(e As PaintEventArgs)
Dim g As Graphics = e.Graphics
' Transparent red, green, and blue brushes.
Dim trnsRedBrush As New SolidBrush(Color.FromArgb(&H78FF0000))
Dim trnsGreenBrush As New SolidBrush(Color.FromArgb(&H7800FF00))
Dim trnsBlueBrush As New SolidBrush(Color.FromArgb(&H780000FF))
' Base and height of the triangle that is used to position the
' circles. Each vertex of the triangle is at the center of one of
' the 3 circles. The base is equal to the diameter of the circle.
Dim triBase As Single = 100
Dim triHeight As Single = CSng(Math.Sqrt((3 *(triBase * _
triBase) / 4)))
' Coordinates of first circle's bounding rectangle.
Dim x1 As Single = 40
Dim y1 As Single = 40
' Fill 3 over-lapping circles. Each circle is a different color.
g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight)
g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight, _
2 * triHeight, 2 * triHeight)
g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, _
2 * triHeight)
End Sub
[C#]
public void FromArgb_3(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Transparent red, green, and blue brushes.
SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(0x78FF0000));
SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(0x7800FF00));
SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(0x780000FF));
// Base and height of the triangle that is used to position the
// circles. Each vertex of the triangle is at the center of one of the
// 3 circles. The base is equal to the diameter of the circles.
float triBase = 100;
float triHeight = (float)Math.Sqrt(3*(triBase*triBase)/4);
// coordinates of first circle's bounding rectangle.
float x1 = 40;
float y1 = 40;
// Fill 3 over-lapping circles. Each circle is a different color.
g.FillEllipse(trnsRedBrush, x1, y1, 2*triHeight, 2*triHeight);
g.FillEllipse(trnsGreenBrush, x1 + triBase/2, y1 + triHeight,
2*triHeight, 2*triHeight);
g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2*triHeight, 2*triHeight);
}
[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 オーバーロードの一覧