Image.GetBounds(GraphicsUnit) Método

Definição

Obtém os limites da imagem na unidade 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

Um dos GraphicsUnit valores que indica a unidade de medida do retângulo delimitador.

Devoluções

O RectangleF que representa os limites da imagem, na unidade especificada.

Exemplos

O exemplo de código seguinte demonstra como carregar um bitmap a partir de um Icon handle, usando a GraphicsUnit enumeração, e como usar o Round método para desenhar os limites retangulares de um bitmap.

Este exemplo foi concebido para ser usado com Windows Forms. Crie um formulário que contenha um botão chamado Button2. Cole o código no formulário e associe este método ao evento do Click botão.

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

Aplica-se a