android bitmap.clone,Bitmap.Clone 方法 (System.Drawing) | Microsoft Docs

Creates a copy of the section of this Bitmap defined by Rectangle structure and with a specified PixelFormat enumeration.

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

參數

定義要複製的這個 Bitmap 的部分。Defines the portion of this Bitmap to copy. 座標相對於這個 Bitmap。Coordinates are relative to this Bitmap.

新 Bitmap 的像素格式。The pixel format for the new Bitmap. 這必須指定以「格式」 開頭的值。This must specify a value that begins with Format.

傳回

這個方法建立的新 Bitmap。The new Bitmap that this method creates.

例外狀況

rect 落在來源點陣圖的外框之外。rect is outside of the source bitmap bounds.

rect 的高度或寬度為 0。The height or width of rect is 0.

-或--or-

指定了 PixelFormat 值,其名稱不是以「格式」開頭。A PixelFormat value is specified whose name does not start with Format. For example, specifying Gdi will cause an ArgumentException, but Format48bppRgb will not.

範例

下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs e 是 Paint 事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式碼會執行下列動作:The code performs the following actions:

從檔案建立 Bitmap 。Creates a Bitmap from a file.

複製其中的一部分 Bitmap 。Clones a portion of that Bitmap.

將複製的部分繪製到螢幕。Draws the cloned portion to the screen.

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

適用於

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值