[Visual Basic, C#] 下面的示例旨在用于 Windows 窗体,它需要 PaintEventArgs e(这是 Paint 事件处理程序的参数)。此代码获取位图中像素的颜色,然后用该颜色填充一个矩形。[Visual Basic] 
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);
}