Evaluar y enviar comentarios

  Encender vista de ancho de banda bajo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
Biblioteca de clases de .NET Framework
Matrix.Reset (Método)

Restablece esta Matrix para que tenga los elementos de la matriz de identidad.

Espacio de nombres: System.Drawing.Drawing2D
Ensamblado: System.Drawing (en system.drawing.dll)

Visual Basic (Declaración)
Public Sub Reset
Visual Basic (Uso)
Dim instance As Matrix

instance.Reset
C#
public void Reset ()
C++
public:
void Reset ()
J#
public void Reset ()
JScript
public function Reset ()

Los elementos en la diagonal principal de la matriz de identidad son 1. Todos los demás elementos de la matriz de identidad son 0.

El siguiente ejemplo de código está pensado para usarse con formularios Windows Forms y requiere PaintEventArgse, un objeto del evento Paint. El código realiza las siguientes acciones:

  • Crea una matriz de escala.

  • Enumera en la pantalla los elementos de la matriz.

  • Restablece la matriz en identidad.

  • Enumera en la pantalla los elementos.

  • Convierte la matriz con 50 puntos en el eje x y 40 puntos en el eje y.

  • Enumera en la pantalla los elementos de la matriz convertida.

  • Dibuja en la pantalla un rectángulo antes de aplicar la transformación de la matriz (rectángulo azul).

  • Aplica la transformación al rectángulo.

  • Dibuja en la pantalla el rectángulo transformado (rectángulo rojo), con las mismas coordenadas que el rectángulo anterior.

Advierta que no ha cambiado el tamaño del rectángulo rojo (por el restablecimiento llevado a cabo) pero se ha convertido en los ejes x e y.

Visual Basic
Public Sub ResetExample(ByVal e As PaintEventArgs)
    Dim myPen As New Pen(Color.Blue, 1)
    Dim myPen2 As New Pen(Color.Red, 1)
    Dim myMatrix As New Matrix(5.0F, 0.0F, 0.0F, 3.0F, 0.0F, 0.0F)

    ListMatrixElementsHelper2(e, myMatrix, "Beginning Matrix", 6, 20)
    myMatrix.Reset()
    ListMatrixElementsHelper(e, myMatrix, "Matrix After Reset", 6, 40)

    ' Translate.
    myMatrix.Translate(50.0F, 40.0F)

    ListMatrixElementsHelper(e, myMatrix, "Matrix After Translation", _
        6, 60)
    e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100)
    e.Graphics.Transform = myMatrix
    e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100)
End Sub

' A helper function to list the contents of a matrix.
Public Sub ListMatrixElementsHelper2(ByVal e As PaintEventArgs, _
ByVal matrix As Matrix, ByVal matrixName As String, ByVal numElements As Integer, _
ByVal y As Integer)

    ' Set up variables for drawing the array
    ' of points to the screen.
    Dim i As Integer
    Dim x As Single = 20
    Dim j As Single = 200
    Dim myFont As New Font("Arial", 8)
    Dim myBrush As New SolidBrush(Color.Black)

    ' Draw the matrix name to the screen.
    e.Graphics.DrawString(matrixName + ":  ", myFont, myBrush, x, y)

    ' Draw the set of path points and types to the screen.
    For i = 0 To numElements - 1
        e.Graphics.DrawString(matrix.Elements(i).ToString() + ", ", _
        myFont, myBrush, j, y)
        j += 30
    Next i
End Sub
C#
public void ResetExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
             
    // Create a matrix that scales by 5 in the x direction and
    // by 3 in the y direction.
    Matrix myMatrix = new Matrix(
        5.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f); 
             
    // List the matrix elements to the screen.
    ListMatrixElements(e, myMatrix, "Beginning Matrix", 6, 20);
             
    // Reset the matrix to identity.
    myMatrix.Reset();
             
    // Again list the matrix elements to the screen.
    ListMatrixElements2(e, myMatrix, "Matrix After Reset", 6, 40);
             
    // Translate the matrix by 50 points in the x-axis and 40 points
    // in the y-axis.
    myMatrix.Translate(50.0f, 40.0f); 
  
    // List the matrix elements to the screen.
    ListMatrixElements1(e, myMatrix, "Matrix After Translation", 6, 60);
             
    // Draw a rectangle to the screen.
    e.Graphics.DrawRectangle(myPen, 0, 0, 100, 100);
             
    // Apply the matrix transform to the Graphics.
    e.Graphics.Transform = myMatrix;
             
    // Draw another rectangle to the screen that has the transform
    // applied.
    e.Graphics.DrawRectangle(myPen2, 0, 0, 100, 100);
}
             
//-------------------------------------------------------
// This function is a helper function to
// list the contents of a matrix.
//-------------------------------------------------------
public void ListMatrixElements2(
    PaintEventArgs e,
    Matrix matrix,
    string matrixName,
    int numElements,
    int y)
{
             
    // Set up variables for drawing the array
    // of points to the screen.
    int i;
    float x = 20, X = 200;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.Black);
             
    // Draw the matrix name to the screen.
    e.Graphics.DrawString(
        matrixName + ":  ",
        myFont,
        myBrush,
        x,
        y);
             
    // Draw the set of path points and types to the screen.
    for(i=0; i < numElements; i++)
    {
        e.Graphics.DrawString(
            matrix.Elements[i].ToString() + ", ",
            myFont,
            myBrush,
            X,
            y);
        X += 30;
    }
}
C++
public:
   void ResetExample( PaintEventArgs^ e )
   {
      Pen^ myPen = gcnew Pen( Color::Blue,1.0f );
      Pen^ myPen2 = gcnew Pen( Color::Red,1.0f );

      // Create a matrix that scales by 5 in the x direction and
      // by 3 in the y direction.
      Matrix^ myMatrix = gcnew Matrix( 5.0f,0.0f,0.0f,3.0f,0.0f,0.0f );

      // List the matrix elements to the screen.
      ListMatrixElements( e, myMatrix, "Beginning Matrix", 6, 20 );

      // Reset the matrix to identity.
      myMatrix->Reset();

      // Again list the matrix elements to the screen.
      ListMatrixElements2( e, myMatrix, "Matrix After Reset", 6, 40 );

      // Translate the matrix by 50 points in the x-axis and 40 points
      // in the y-axis.
      myMatrix->Translate( 50.0f, 40.0f );

      // List the matrix elements to the screen.
      ListMatrixElements1( e, myMatrix, "Matrix After Translation", 6, 60 );

      // Draw a rectangle to the screen.
      e->Graphics->DrawRectangle( myPen, 0, 0, 100, 100 );

      // Apply the matrix transform to the Graphics.
      e->Graphics->Transform = myMatrix;

      // Draw another rectangle to the screen that has the transform
      // applied.
      e->Graphics->DrawRectangle( myPen2, 0, 0, 100, 100 );
   }

   //-------------------------------------------------------
   // This function is a helper function to
   // list the contents of a matrix.
   //-------------------------------------------------------
   void ListMatrixElements2( PaintEventArgs^ e, Matrix^ matrix, String^ matrixName, int numElements, int y )
   {
      // Set up variables for drawing the array
      // of points to the screen.
      int i;
      float x = 20,X = 200;
      System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",8 );
      SolidBrush^ myBrush = gcnew SolidBrush( Color::Black );

      // Draw the matrix name to the screen.
      e->Graphics->DrawString( String::Concat( matrixName, ":  " ), myFont, myBrush, (float)x, (float)y );

      // Draw the set of path points and types to the screen.
      for ( i = 0; i < numElements; i++ )
      {
         e->Graphics->DrawString( String::Concat( matrix->Elements[ i ], ", " ), myFont, myBrush, (float)X, (float)y );
         X += 30;
      }
   }
J#
public void ResetExample(PaintEventArgs e)
{
    Pen myPen = new Pen(Color.get_Blue(), 1);
    Pen myPen2 = new Pen(Color.get_Red(), 1);

    // Create a matrix that scales by 5 in the x direction and
    // by 3 in the y direction.
    Matrix myMatrix = new Matrix(5, 0, 0, 3, 0, 0);

    // List the matrix elements to the screen.
    ListMatrixElements(e, myMatrix, "Beginning Matrix", 6, 20);

    // Reset the matrix to identity.
    myMatrix.Reset();

    // Again list the matrix elements to the screen.
    ListMatrixElements2(e, myMatrix, "Matrix After Reset", 6, 40);

    // Translate the matrix by 50 points in the x-axis and 40 points
    // in the y-axis.
    myMatrix.Translate(50, 40);

    // List the matrix elements to the screen.
    ListMatrixElements1(e, myMatrix, "Matrix After Translation", 6, 60);

    // Draw a rectangle to the screen.
    e.get_Graphics().DrawRectangle(myPen, 0, 0, 100, 100);

    // Apply the matrix transform to the Graphics.
    e.get_Graphics().set_Transform(myMatrix);

    // Draw another rectangle to the screen that has the transform
    // applied.
    e.get_Graphics().DrawRectangle(myPen2, 0, 0, 100, 100);
} //ResetExample

//-------------------------------------------------------
// This function is a helper function to
// list the contents of a matrix.
//-------------------------------------------------------
public void ListMatrixElements2(PaintEventArgs e, Matrix matrix, 
    String matrixName, int numElements, int y)
{
    // Set up variables for drawing the array
    // of points to the screen.
    int i;
    float x = 20;
    float X = 200;
    Font myFont = new Font("Arial", 8);
    SolidBrush myBrush = new SolidBrush(Color.get_Black());

    // Draw the matrix name to the screen.
    e.get_Graphics().DrawString(matrixName + ":  ", myFont, myBrush, x, y);

    // Draw the set of path points and types to the screen.
    for (i = 0; i < numElements; i++) {
        e.get_Graphics().DrawString(
            matrix.get_Elements().get_Item(i).ToString() + ", ", myFont, 
            myBrush, X, y);
        X += 30;
    }
} //ListMatrixElements2

Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0, 1.1, 1.0
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2009 Microsoft Corporation. Reservados todos los derechos. Términos de uso  |  Marcas Registradas  |  Privacidad
Page view tracker