Image.GetBounds(GraphicsUnit) Méthode

Définition

Obtient les limites de l'image dans l'unité spécifiée.

public:
 System::Drawing::RectangleF GetBounds(System::Drawing::GraphicsUnit % pageUnit);
public System.Drawing.RectangleF GetBounds (ref System.Drawing.GraphicsUnit pageUnit);
member this.GetBounds : GraphicsUnit -> System.Drawing.RectangleF
Public Function GetBounds (ByRef pageUnit As GraphicsUnit) As RectangleF

Paramètres

pageUnit
GraphicsUnit

Une des valeurs de GraphicsUnit indiquant l'unité de mesure du rectangle englobant.

Retours

RectangleF représentant les limites de l'image, dans l'unité spécifiée.

Exemples

L’exemple de code suivant montre comment charger une bitmap à partir d’un Icon handle, à l’aide de l’énumération GraphicsUnit , et comment utiliser la Round méthode pour dessiner les limites de rectangle d’une bitmap.

Cet exemple est conçu pour être utilisé avec Windows Forms. Créez un formulaire qui contient un bouton nommé Button2. Collez le code dans le formulaire et associez cette méthode à l’événement du Click bouton.

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( units );
   Rectangle bmpRectangle = Rectangle::Round( bmpRectangleF );
   formGraphics->DrawRectangle( Pens::Blue, bmpRectangle );
   delete formGraphics;
}
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();
}
Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    Dim bitmap1 As Bitmap = Bitmap.FromHicon(SystemIcons.Hand.Handle)
    Dim formGraphics As Graphics = Me.CreateGraphics()
    Dim units As GraphicsUnit = GraphicsUnit.Point
    Dim bmpRectangleF As RectangleF = bitmap1.GetBounds(units)
    Dim bmpRectangle As Rectangle = Rectangle.Round(bmpRectangleF)
    formGraphics.DrawRectangle(Pens.Blue, bmpRectangle)
    formGraphics.Dispose()
End Sub

S’applique à