次の方法で共有


Bitmap.SetPixel メソッド

この Bitmap オブジェクトの指定のピクセルの色を設定します。

Public Sub SetPixel( _
   ByVal x As Integer, _   ByVal y As Integer, _   ByVal color As Color _)
[C#]
public void SetPixel(intx,inty,Colorcolor);
[C++]
public: void SetPixel(intx,inty,Colorcolor);
[JScript]
public function SetPixel(
   x : int,y : int,color : Color);

パラメータ

  • x
    設定するピクセルの x 座標。
  • y
    設定するピクセルの y 座標。
  • color
    指定のピクセルに割り当てる色を表す Color 構造体。

戻り値

このメソッドは値を返しません。

使用例

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

  • Bitmap オブジェクトを作成します。
  • ビットマップの各ピクセルの色を黒に設定します。
  • ビットマップを描画します。
 
Public Sub SetPixel_Example(e As PaintEventArgs)
' Create a Bitmap object from a file.
Dim myBitmap As New Bitmap("Grapes.jpg")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
' Set each pixel in myBitmap to black.
Dim Xcount As Integer
For Xcount = 0 To myBitmap.Width - 1
Dim Ycount As Integer
For Ycount = 0 To myBitmap.Height - 1
myBitmap.SetPixel(Xcount, Ycount, Color.Black)
Next Ycount
Next Xcount
' Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
myBitmap.Height)
End Sub
        
[C#] 
public void SetPixel_Example(PaintEventArgs e)
{
// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(
myBitmap,
0,
0,
myBitmap.Width,
myBitmap.Height);
// Set each pixel in myBitmap to black.
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Black);
}
}
// Draw myBitmap to the screen again.
e.Graphics.DrawImage(
myBitmap,
myBitmap.Width,
0,
myBitmap.Width,
myBitmap.Height);
}
        

[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 名前空間