Bitmap.GetPixel(Int32, Int32) 메서드

정의

Bitmap값에서 지정된 픽셀의 색을 가져옵니다.

public:
 System::Drawing::Color GetPixel(int x, int y);
public System.Drawing.Color GetPixel(int x, int y);
member this.GetPixel : int * int -> System.Drawing.Color
Public Function GetPixel (x As Integer, y As Integer) As Color

매개 변수

x
Int32

검색할 픽셀의 x 좌표입니다.

y
Int32

검색할 픽셀의 y 좌표입니다.

반품

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

예외

x 가 0보다 작거나 Width.

-또는-

y 가 0보다 작거나 Height.

작업이 실패했습니다.

예제

다음 코드 예제는 Windows Forms 사용하도록 설계되었으며 PaintEventArgs 이벤트 처리기의 매개 변수인 ePaint 필요합니다. 코드는 비트맵에서 픽셀의 색을 가져오고 해당 색으로 사각형을 채웁니다.

private:
   void GetPixel_Example( PaintEventArgs^ e )
   {
      // Create a Bitmap object from an image file.
      Bitmap^ myBitmap = gcnew Bitmap( "Grapes.jpg" );

      // Get the color of a pixel within myBitmap.
      Color pixelColor = myBitmap->GetPixel( 50, 50 );

      // Fill a rectangle with pixelColor.
      SolidBrush^ pixelBrush = gcnew SolidBrush( pixelColor );
      e->Graphics->FillRectangle( pixelBrush, 0, 0, 100, 100 );
   }
private void GetPixel_Example(PaintEventArgs e)
{

    // Create a Bitmap object from an image file.
    Bitmap 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);
}
Private Sub GetPixel_Example(ByVal 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

적용 대상