Partage via


Bitmap.Clone Méthode

Définition

Crée une copie de la section de cette Bitmap définie avec un PixelFormatspécifié.

Surcharges

Clone(RectangleF, PixelFormat)

Crée une copie de la section de cette Bitmap définie avec une énumération PixelFormat spécifiée.

Clone(Rectangle, PixelFormat)

Crée une copie de la section de cette Bitmap définie par Rectangle structure et avec une énumération PixelFormat spécifiée.

Clone(RectangleF, PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

Crée une copie de la section de cette Bitmap définie avec une énumération PixelFormat spécifiée.

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

Paramètres

rect
RectangleF

Définit la partie de cette Bitmap à copier.

format
PixelFormat

Spécifie l’énumération PixelFormat pour le Bitmapde destination.

Retours

La Bitmap créée par cette méthode.

Exceptions

rect est en dehors des limites bitmap sources.

La hauteur ou la largeur de rect est de 0.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du gestionnaire d’événements Paint. Le code effectue les actions suivantes :

  • Crée un Bitmap à partir d’un fichier.

  • Clone une partie de cette Bitmap.

  • Dessine la partie cloné à l’écran.

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

S’applique à

Clone(Rectangle, PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

Crée une copie de la section de cette Bitmap définie par Rectangle structure et avec une énumération PixelFormat spécifiée.

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

Paramètres

rect
Rectangle

Définit la partie de cette Bitmap à copier. Les coordonnées sont relatives à cette Bitmap.

format
PixelFormat

Format de pixel pour la nouvelle Bitmap. Cela doit spécifier une valeur qui commence par Format.

Retours

Nouvelle Bitmap créée par cette méthode.

Exceptions

rect est en dehors des limites bitmap sources.

La hauteur ou la largeur de rect est de 0.

-ou-

Une valeur PixelFormat est spécifiée dont le nom ne commence pas par Format. Par exemple, la spécification de Gdi entraîne une ArgumentException, mais Format48bppRgb ne le fera pas.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du gestionnaire d’événements Paint. Le code effectue les actions suivantes :

  • Crée un Bitmap à partir d’un fichier.

  • Clone une partie de cette Bitmap.

  • Dessine la partie cloné à l’écran.

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

S’applique à