This documentation is archived and is not being maintained.

Bitmap.Clone Method

Creates a copy of the section of this Bitmap defined with a specified PixelFormat.

Overload List

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

[Visual Basic] Overloads Public Function Clone(Rectangle, PixelFormat) As Bitmap
[C#] public Bitmap Clone(Rectangle, PixelFormat);
[C++] public: Bitmap* Clone(Rectangle, PixelFormat);
[JScript] public function Clone(Rectangle, PixelFormat) : Bitmap;

Creates a copy of the section of this Bitmap object defined with a specified PixelFormat enumeration.

[Visual Basic] Overloads Public Function Clone(RectangleF, PixelFormat) As Bitmap
[C#] public Bitmap Clone(RectangleF, PixelFormat);
[C++] public: Bitmap* Clone(RectangleF, PixelFormat);
[JScript] public function Clone(RectangleF, PixelFormat) : Bitmap;

Inherited from Image.

[Visual Basic] Overloads Public Overridable Function Clone() As Object Implements ICloneable.Clone
[C#] public virtual object Clone();
[C++] public: virtual Object* Clone();
[JScript] public function Clone() : Object;

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates a Bitmap object from a file.
  • Clones a portion of that Bitmap object.
  • Draws the cloned portion to the screen.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of Clone. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub Clone_Example(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
        
[C#] 
public void Clone_Example(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);
PixelFormat format = myBitmap.PixelFormat;
Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);
// Draw the cloned portion of the Bitmap object.
e.Graphics.DrawImage(cloneBitmap, 0, 0);
}
        

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Bitmap Class | Bitmap Members | System.Drawing Namespace

Show: