Bitmap.Clone Método

Definição

Cria uma cópia da seção desse Bitmap definida com um PixelFormat especificado.Creates a copy of the section of this Bitmap defined with a specified PixelFormat.

Sobrecargas

Clone(RectangleF, PixelFormat)

Cria uma cópia da seção desse Bitmap definida com uma enumeração PixelFormat especificada.Creates a copy of the section of this Bitmap defined with a specified PixelFormat enumeration.

Clone(Rectangle, PixelFormat)

Cria uma cópia da seção deste Bitmap definida pela estrutura Rectangle e com uma enumeração PixelFormat especificada.Creates a copy of the section of this Bitmap defined by Rectangle structure and with a specified PixelFormat enumeration.

Clone(RectangleF, PixelFormat)

Cria uma cópia da seção desse Bitmap definida com uma enumeração PixelFormat especificada.Creates a copy of the section of this Bitmap defined with a specified PixelFormat enumeration.

public:
 System::Drawing::Bitmap ^ Clone(System::Drawing::RectangleF rect, System::Drawing::Imaging::PixelFormat format);
public System.Drawing.Bitmap Clone (System.Drawing.RectangleF rect, System.Drawing.Imaging.PixelFormat format);
override this.Clone : System.Drawing.RectangleF * System.Drawing.Imaging.PixelFormat -> System.Drawing.Bitmap
Public Function Clone (rect As RectangleF, format As PixelFormat) As Bitmap

Parâmetros

rect
RectangleF

Define a parte desse Bitmap a ser copiada.Defines the portion of this Bitmap to copy.

format
PixelFormat

Especifica a enumeração PixelFormat para o destino Bitmap.Specifies the PixelFormat enumeration for the destination Bitmap.

Retornos

Bitmap

O Bitmap criado por esse método.The Bitmap that this method creates.

Exceções

rect está fora dos limites do bitmap de origem.rect is outside of the source bitmap bounds.

A altura ou largura de rect é 0.The height or width of rect is 0.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms, e ele requer PaintEventArgs e , que é um parâmetro do Paint manipulador de eventos.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. O código executa as seguintes ações:The code performs the following actions:

  • Cria um Bitmap de um arquivo.Creates a Bitmap from a file.

  • Clona uma parte disso Bitmap .Clones a portion of that Bitmap.

  • Desenha a parte clonada na tela.Draws the cloned portion to the screen.

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

      // Clone a portion of the Bitmap object.
      RectangleF cloneRect = RectangleF(0,0,100,100);
      System::Drawing::Imaging::PixelFormat format = myBitmap->PixelFormat;
      Bitmap^ cloneBitmap = myBitmap->Clone( cloneRect, format );

      // Draw the cloned portion of the Bitmap object.
      e->Graphics->DrawImage( cloneBitmap, 0, 0 );
   }
private void Clone_Example2(PaintEventArgs e)
{

    // Create a Bitmap object from a file.
    Bitmap myBitmap = new Bitmap("Grapes.jpg");

    // Clone a portion of the Bitmap object.
    RectangleF cloneRect = new RectangleF(0, 0, 100, 100);
    System.Drawing.Imaging.PixelFormat format =
        myBitmap.PixelFormat;
    Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);

    // Draw the cloned portion of the Bitmap object.
    e.Graphics.DrawImage(cloneBitmap, 0, 0);
}
Private Sub Clone_Example2(ByVal e As PaintEventArgs)

    ' Create a Bitmap object from a file.
    Dim myBitmap As New Bitmap("Grapes.jpg")

    ' Clone a portion of the Bitmap object.
    Dim cloneRect As New RectangleF(0, 0, 100, 100)
    Dim format As PixelFormat = myBitmap.PixelFormat
    Dim cloneBitmap As Bitmap = myBitmap.Clone(cloneRect, format)

    ' Draw the cloned portion of the Bitmap object.
    e.Graphics.DrawImage(cloneBitmap, 0, 0)
End Sub

Aplica-se a

Clone(Rectangle, PixelFormat)

Cria uma cópia da seção deste Bitmap definida pela estrutura Rectangle e com uma enumeração PixelFormat especificada.Creates a copy of the section of this Bitmap defined by Rectangle structure and with a specified PixelFormat enumeration.

public:
 System::Drawing::Bitmap ^ Clone(System::Drawing::Rectangle rect, System::Drawing::Imaging::PixelFormat format);
public System.Drawing.Bitmap Clone (System.Drawing.Rectangle rect, System.Drawing.Imaging.PixelFormat format);
override this.Clone : System.Drawing.Rectangle * System.Drawing.Imaging.PixelFormat -> System.Drawing.Bitmap
Public Function Clone (rect As Rectangle, format As PixelFormat) As Bitmap

Parâmetros

rect
Rectangle

Define a parte desse Bitmap a ser copiada.Defines the portion of this Bitmap to copy. As coordenadas são relativas a esse Bitmap.Coordinates are relative to this Bitmap.

format
PixelFormat

O formato de pixel para o novo Bitmap.The pixel format for the new Bitmap. Isso deve especificar um valor que começa com Format.This must specify a value that begins with Format.

Retornos

Bitmap

O novo Bitmap criado por esse método.The new Bitmap that this method creates.

Exceções

rect está fora dos limites do bitmap de origem.rect is outside of the source bitmap bounds.

A altura ou largura de rect é 0.The height or width of rect is 0.

- ou --or- Um valor PixelFormat foi especificado, cujo nome não começa com Format.A PixelFormat value is specified whose name does not start with Format. Por exemplo, especificar Gdi causará um ArgumentException, mas Format48bppRgb não.For example, specifying Gdi will cause an ArgumentException, but Format48bppRgb will not.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms, e ele requer PaintEventArgs e , que é um parâmetro do Paint manipulador de eventos.The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. O código executa as seguintes ações:The code performs the following actions:

  • Cria um Bitmap de um arquivo.Creates a Bitmap from a file.

  • Clona uma parte disso Bitmap .Clones a portion of that Bitmap.

  • Desenha a parte clonada na tela.Draws the cloned portion to the screen.

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

      // Clone a portion of the Bitmap object.
      Rectangle cloneRect = Rectangle(0,0,100,100);
      System::Drawing::Imaging::PixelFormat format = myBitmap->PixelFormat;
      Bitmap^ cloneBitmap = myBitmap->Clone( cloneRect, format );

      // Draw the cloned portion of the Bitmap object.
      e->Graphics->DrawImage( cloneBitmap, 0, 0 );
   }
private void Clone_Example1(PaintEventArgs e)
{

    // Create a Bitmap object from a file.
    Bitmap myBitmap = new Bitmap("Grapes.jpg");

    // Clone a portion of the Bitmap object.
    Rectangle cloneRect = new Rectangle(0, 0, 100, 100);
    System.Drawing.Imaging.PixelFormat format =
        myBitmap.PixelFormat;
    Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);

    // Draw the cloned portion of the Bitmap object.
    e.Graphics.DrawImage(cloneBitmap, 0, 0);
}
Private Sub Clone_Example1(ByVal e As PaintEventArgs)

    ' Create a Bitmap object from a file.
    Dim myBitmap As New Bitmap("Grapes.jpg")

    ' Clone a portion of the Bitmap object.
    Dim cloneRect As New Rectangle(0, 0, 100, 100)
    Dim format As PixelFormat = myBitmap.PixelFormat
    Dim cloneBitmap As Bitmap = myBitmap.Clone(cloneRect, format)

    ' Draw the cloned portion of the Bitmap object.
    e.Graphics.DrawImage(cloneBitmap, 0, 0)
End Sub

Aplica-se a