Bitmap.SetPixel(Int32, Int32, Color) 메서드

정의

Bitmap값에서 지정된 픽셀의 색을 설정합니다.

public:
 void SetPixel(int x, int y, System::Drawing::Color color);
public void SetPixel(int x, int y, System.Drawing.Color color);
member this.SetPixel : int * int * System.Drawing.Color -> unit
Public Sub SetPixel (x As Integer, y As Integer, color As Color)

매개 변수

x
Int32

설정할 픽셀의 x 좌표입니다.

y
Int32

설정할 픽셀의 y 좌표입니다.

color
Color

Color 지정된 픽셀에 할당할 색을 나타내는 구조체입니다.

예외

작업이 실패했습니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 PaintEventArgs 이벤트 처리기의 매개 변수인 ePaint 필요합니다. 코드는 다음 작업을 수행합니다.

  • Bitmap 항목을 만듭니다.

  • 비트맵에서 각 픽셀의 색을 검정으로 설정합니다.

  • 비트맵을 그립니다.

private:
   void SetPixel_Example( PaintEventArgs^ e )
   {
      // Create a Bitmap object from a file.
      Bitmap^ myBitmap = gcnew 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 );
   }
private 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);
}
Private Sub SetPixel_Example(ByVal 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

설명

메서드를 사용하여 SetPixel 프로그래밍 방식으로 이미지에서 개별 픽셀의 색을 설정합니다. 메서드를 사용하여 LockBits 프로그래밍 방식으로 이미지를 변경할 수도 있습니다. 일반적으로 대규모 변경의 경우 이 메서드는 LockBits 더 나은 성능을 제공합니다.

적용 대상