Image.GetBounds(GraphicsUnit) Método

Definición

Obtiene los límites de la imagen en la unidad especificada.

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

Parámetros

pageUnit
GraphicsUnit

Uno de los valores GraphicsUnit que indica la unidad de medida del rectángulo delimitador.

Devoluciones

RectangleF que representa los límites de la imagen en la unidad especificada.

Ejemplos

En el ejemplo de código siguiente se muestra cómo cargar un mapa de bits desde un Icon identificador, mediante la GraphicsUnit enumeración y cómo usar el Round método para dibujar los límites del rectángulo de un mapa de bits.

Este ejemplo está diseñado para usarse con Windows Forms. Cree un formulario que contenga un botón denominado Button2. Pegue el código en el formulario y asocie este método con el evento del Click botón.

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

Se aplica a