語言

Bitmap.Clone 方法

定義

建立定義中指定 Bitmap的 的該段PixelFormat的副本。

多載

名稱 Description
Clone(RectangleF, PixelFormat)

建立定義中以指定Bitmap列舉方式的區段PixelFormat副本。

Clone(Rectangle, PixelFormat)

建立由Bitmap結構定義的該區段Rectangle的副本,並附上指定的PixelFormat列舉。

Clone(RectangleF, PixelFormat)

來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs

建立定義中以指定Bitmap列舉方式的區段PixelFormat副本。

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

參數

rect
RectangleF

定義了複製的部分 Bitmap 。

format
PixelFormat

指定 PixelFormat 目的地 Bitmap的枚舉。

傳回

這個 Bitmap 方法所產生的。

例外狀況

rect 超出來源位圖範圍。

的 rect 高度或寬度為0。

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 此程式碼會執行下列動作:

  • 從檔案建立一個 Bitmap 。

  • 複製了其中 Bitmap一部分。

  • 把複製出來的部分畫到螢幕上。

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

適用於

Clone(Rectangle, PixelFormat)

來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs

建立由Bitmap結構定義的該區段Rectangle的副本,並附上指定的PixelFormat列舉。

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

參數

rect
Rectangle

定義了複製的部分 Bitmap 。 座標相對於此 Bitmap為參考。

format
PixelFormat

新的 Bitmap. 這必須指定一個以 Format為開頭的值。

傳回

這種方法帶來的新事物 Bitmap 。

例外狀況

rect 超出來源位圖範圍。

的 rect 高度或寬度為0。

-或-

指定一個 PixelFormat 名稱不以 Format 開頭的值。 例如,指定 Gdi 會產生 ArgumentException,但 Format48bppRgb 不會。

範例

以下程式碼範例是為 Windows Forms 設計的,並需要 PaintEventArgse,這是 Paint 事件處理程序的參數。 此程式碼會執行下列動作:

  • 從檔案建立一個 Bitmap 。

  • 複製了其中 Bitmap一部分。

  • 把複製出來的部分畫到螢幕上。

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

適用於