Bitmap.Clone 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立這個區段的複本,此 Bitmap 以指定的 PixelFormat所定義。
多載
Clone(RectangleF, PixelFormat) |
建立這個 Bitmap 區段的複本,此區段是使用指定的 PixelFormat 列舉所定義。 |
Clone(Rectangle, PixelFormat) |
使用指定的 PixelFormat 列舉,建立這個 BitmapRectangle 結構所定義的區段複本。 |
Clone(RectangleF, PixelFormat)
- 來源:
- 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
指定目的地 Bitmap的 PixelFormat 列舉。
傳回
這個方法所建立的 Bitmap。
例外狀況
rect
位於來源位圖界限之外。
rect
的高度或寬度為 0。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
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
使用指定的 PixelFormat 列舉,建立這個 BitmapRectangle 結構所定義的區段複本。
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
參數
- format
- PixelFormat
新 Bitmap的像素格式。 這必須指定以 Format
開頭的值。
傳回
這個方法所建立的新 Bitmap。
例外狀況
rect
位於來源位圖界限之外。
rect
的高度或寬度為 0。
-或-
指定 PixelFormat 值,其名稱不是以 Format開頭。 例如,指定 Gdi 會導致 ArgumentException,但 Format48bppRgb 不會。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
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