次の方法で共有


Bitmap.GetPixel メソッド

この Bitmap の指定したピクセルの色を取得します。

Public Function GetPixel( _
   ByVal x As Integer, _   ByVal y As Integer _) As Color
[C#]
public Color GetPixel(intx,inty);
[C++]
public: Color GetPixel(intx,inty);
[JScript]
public function GetPixel(
   x : int,y : int) : Color;

パラメータ

  • x
    取得するピクセルの x 座標。
  • y
    取得するピクセルの y 座標。

戻り値

指定したピクセルの色を表す Color 構造体。

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードでは、ビットマップのピクセルの色を取得し、その色で四角形を塗りつぶします。

 
Public Sub GetPixel_Example(e As PaintEventArgs)
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("Grapes.jpg")
' Get the color of a pixel within myBitmap.
Dim pixelColor As Color = myBitmap.GetPixel(50, 50)
' Fill a rectangle with pixelColor.
Dim pixelBrush As New SolidBrush(pixelColor)
e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100)
End Sub
        
[C#] 
public void GetPixel_Example(PaintEventArgs e)
{
// Create a Bitmap object from an image file.
Bimap myBitmap = new Bitmap("Grapes.jpg");
// Get the color of a pixel within myBitmap.
Color pixelColor = myBitmap.GetPixel(50, 50);
// Fill a rectangle with pixelColor.
SolidBrush pixelBrush = new SolidBrush(pixelColor);
e.Graphics.FillRectangle(pixelBrush, 0, 0, 100, 100);
}
        

[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

参照

Bitmap クラス | Bitmap メンバ | System.Drawing 名前空間