Bitmap.GetPixel(Int32, Int32) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém a cor do pixel especificado neste 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
Parâmetros
- x
- Int32
A coordenada x do píxel a recuperar.
- y
- Int32
A coordenada y do píxel a recuperar.
Devoluções
Uma Color estrutura que representa a cor do pixel especificado.
Exceções
A operação falhou.
Exemplos
O seguinte exemplo de código foi concebido para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do tratador de eventos Paint. O código recebe a cor de um pixel num bitmap e depois preenche um retângulo com essa cor.
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