Share via


Bitmap.Clone Metoda

Definice

Vytvoří kopii tohoto Bitmap oddílu definovaného se zadaným PixelFormatobjektem .

Přetížení

Clone(RectangleF, PixelFormat)

Vytvoří kopii tohoto Bitmap oddílu definovaného se zadaným PixelFormat výčtem.

Clone(Rectangle, PixelFormat)

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

Clone(RectangleF, PixelFormat)

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

Vytvoří kopii tohoto Bitmap oddílu definovaného se zadaným PixelFormat výčtem.

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, Bitmap která se má kopírovat.

format
PixelFormat

Určuje PixelFormat výčet pro cíl Bitmap.

Návraty

Hodnota 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 model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Vytvoří ze Bitmap souboru.

  • Naklonuje část tohoto souboru 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

Vytvoří kopii tohoto oddílu definovaného Bitmap strukturou Rectangle 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, Bitmap která se má kopírovat. Souřadnice jsou relativní k tomuto Bitmap.

format
PixelFormat

Formát pixelu pro nový Bitmap. Tím musí být zadána hodnota, která začíná na Format.

Návraty

Nový Bitmap , který 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 PixelFormat hodnota, jejíž název nezačíná na Formát. Například zadání Gdi způsobí ArgumentException, ale Format48bppRgb ne.

Příklady

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

  • Vytvoří ze Bitmap souboru.

  • Naklonuje část tohoto souboru 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