Bitmap.GetPixel-Methode
Ruft die Farbe des angegebenen Pixels in dieser Bitmap ab.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Function GetPixel ( _
x As Integer, _
y As Integer _
) As Color
'Usage
Dim instance As Bitmap
Dim x As Integer
Dim y As Integer
Dim returnValue As Color
returnValue = instance.GetPixel(x, y)
public Color GetPixel (
int x,
int y
)
public:
Color GetPixel (
int x,
int y
)
public Color GetPixel (
int x,
int y
)
public function GetPixel (
x : int,
y : int
) : Color
Parameter
- x
Die x-Koordinate des abzurufenden Pixels.
- y
Die y-Koordinate des abzurufenden Pixels.
Rückgabewert
Eine Color-Struktur, die die Farbe des angegebenen Pixels darstellt.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
x ist kleiner als 0 oder größer oder gleich Width. oder y ist kleiner als 0 oder größer oder gleich Height |
|
Der Vorgang ist fehlgeschlagen. |
Beispiel
Das folgende Codebeispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code ruft die Farbe eines Pixels in einer Bitmap ab und füllt dann das Rechteck mit dieser Farbe.
Public 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
public 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);
}
public:
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 );
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0