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 窗体一起使用,并且它需要作为 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.
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
适用于