Image.GetBounds(GraphicsUnit) Metodo

Definizione

Ottiene i limiti dell'immagine nell'unità di misura specificata.

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

Parametri

pageUnit
GraphicsUnit

Uno dei valori di GraphicsUnit che indica l'unità di misura per il rettangolo di delimitazione.

Restituisce

Oggetto RectangleF che rappresenta i limiti dell'immagine nell'unità di misura specificata.

Esempio

L'esempio di codice seguente illustra come caricare una bitmap da un Icon handle, usando l'enumerazione GraphicsUnit e come usare il Round metodo per disegnare i limiti rettangoli di una bitmap.

Questo esempio è progettato per essere usato con Windows Forms. Create un modulo contenente un pulsante denominato Button2. Incollare il codice nel modulo e associare questo metodo all'evento del Click pulsante.

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();
}

Si applica a

Prodotto Versioni
.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