英語で読む

次の方法で共有


Image.GetBounds(GraphicsUnit) メソッド

定義

指定した単位でイメージの境界を取得します。

C#
public System.Drawing.RectangleF GetBounds (ref System.Drawing.GraphicsUnit pageUnit);

パラメーター

pageUnit
GraphicsUnit

外接する四角形の長さの単位を示す GraphicsUnit 値のいずれか。

戻り値

指定した単位でイメージの境界を表す RectangleF

次のコード例では、ハンドルから Icon ビットマップを読み込む方法、列挙型を GraphicsUnit 使用する方法、および メソッドを使用 Round してビットマップの四角形の境界を描画する方法を示します。

この例は、Windows フォームで使用するように設計されています。 という名前Button2のボタンを含むフォームをCreateします。 コードをフォームに貼り付け、このメソッドをボタンの Click イベントに関連付けます。

C#
private void Button2_Click(System.Object sender, System.EventArgs e)
{

    Bitmap bitmap1 = Bitmap.FromHicon(SystemIcons.Hand.Handle);
    Graphics formGraphics = this.CreateGraphics();
    GraphicsUnit units = GraphicsUnit.Point;

    RectangleF bmpRectangleF = bitmap1.GetBounds(ref units);
    Rectangle bmpRectangle = Rectangle.Round(bmpRectangleF);
    formGraphics.DrawRectangle(Pens.Blue, bmpRectangle);
    formGraphics.Dispose();
}

適用対象

製品 バージョン
.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
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9