Sdílet prostřednictvím


Bitmap.Clone Metoda

Definice

Vytvoří kopii oddílu této Bitmap definované se zadaným PixelFormat.

Přetížení

Clone(RectangleF, PixelFormat)

Vytvoří kopii oddílu této Bitmap definované pomocí zadaného PixelFormat výčtu.

Clone(Rectangle, PixelFormat)

Vytvoří kopii oddílu této Bitmap definované Rectangle strukturou a se zadaným PixelFormat výčtem.

Clone(RectangleF, PixelFormat)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Vytvoří kopii oddílu této Bitmap definované pomocí zadaného PixelFormat výčtu.

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

Parametry

rect
RectangleF

Definuje část tohoto Bitmap ke kopírování.

format
PixelFormat

Určuje PixelFormat výčtu pro cílový Bitmap.

Návraty

Bitmap, kterou tato metoda vytvoří.

Výjimky

rect je mimo hranice zdrojového rastrového obrázku.

Výška nebo šířka rect je 0.

Příklady

Následující příklad kódu je určený pro použití s Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny události Paint. Kód provede následující akce:

  • Vytvoří Bitmap ze souboru.

  • Klonuje část této Bitmap.

  • Nakreslí klonovanou část na obrazovku.

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

Platí pro

Clone(Rectangle, PixelFormat)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Vytvoří kopii oddílu této Bitmap definované Rectangle strukturou a se zadaným PixelFormat výčtem.

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

Parametry

rect
Rectangle

Definuje část tohoto Bitmap ke kopírování. Souřadnice jsou relativní k tomuto Bitmap.

format
PixelFormat

Formát pixelu pro nový Bitmap. Musí zadat hodnotu, která začíná Format.

Návraty

Nová Bitmap, kterou tato metoda vytvoří.

Výjimky

rect je mimo hranice zdrojového rastrového obrázku.

Výška nebo šířka rect je 0.

-nebo-

Je zadána hodnota PixelFormat, jejíž název nezačíná Formát. Například zadání Gdi způsobí ArgumentException, ale Format48bppRgb nebude.

Příklady

Následující příklad kódu je určený pro použití s Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny události Paint. Kód provede následující akce:

  • Vytvoří Bitmap ze souboru.

  • Klonuje část této Bitmap.

  • Nakreslí klonovanou část na obrazovku.

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

Platí pro