次の方法で共有


Bitmap.Clone メソッド

指定された PixelFormat で定義されたこの Bitmap のセクションのコピーを作成します。

オーバーロードの一覧

Rectangle 構造と、指定された PixelFormat 列挙体で定義されたこの Bitmap オブジェクトのセクションのコピーを作成します。

[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;

指定された PixelFormat 列挙体で定義されたこの Bitmap オブジェクトのセクションのコピーを作成します。

[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;

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;

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • ファイルから Bitmap オブジェクトを作成します。
  • その Bitmap オブジェクトの一部分のクローンを作成します。
  • クローン作成した部分を画面に描画します。

[Visual Basic, C#] メモ   ここでは、Clone のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Bitmap クラス | Bitmap メンバ | System.Drawing 名前空間