Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


Bitmap.Clone Method

Definition

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

Overloads

Clone(RectangleF, PixelFormat)

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

Clone(Rectangle, PixelFormat)

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

Clone(RectangleF, PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

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

C#
public System.Drawing.Bitmap Clone(System.Drawing.RectangleF rect, System.Drawing.Imaging.PixelFormat format);

Parameters

rect
RectangleF

Defines the portion of this Bitmap to copy.

format
PixelFormat

Specifies the PixelFormat enumeration for the destination Bitmap.

Returns

The Bitmap that this method creates.

Exceptions

rect is outside of the source bitmap bounds.

The height or width of rect is 0.

Examples

The following code 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 from a file.

  • Clones a portion of that Bitmap.

  • Draws the cloned portion to the screen.

C#
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);
}

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Clone(Rectangle, PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

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

C#
public System.Drawing.Bitmap Clone(System.Drawing.Rectangle rect, System.Drawing.Imaging.PixelFormat format);

Parameters

rect
Rectangle

Defines the portion of this Bitmap to copy. Coordinates are relative to this Bitmap.

format
PixelFormat

The pixel format for the new Bitmap. This must specify a value that begins with Format.

Returns

The new Bitmap that this method creates.

Exceptions

rect is outside of the source bitmap bounds.

The height or width of rect is 0.

-or-

A PixelFormat value is specified whose name does not start with Format. For example, specifying Gdi will cause an ArgumentException, but Format48bppRgb will not.

Examples

The following code 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 from a file.

  • Clones a portion of that Bitmap.

  • Draws the cloned portion to the screen.

C#
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);
}

Applies to

.NET 10 (package-provided) és más verziók
Termék Verziók
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10