Califique este contenido
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2008/.NET Framework 3.5

Hay además otras versiones disponibles para:
Programación con formularios Windows Forms
Cómo: Representar imágenes con GDI+

Actualización: noviembre 2007

La interfaz GDI+ puede usarse para representar imágenes que existan como archivos en las aplicaciones. Para ello hay que crear un nuevo objeto de una clase Image (como Bitmap), crear un objeto Graphics que haga referencia a la superficie de dibujo que se desea utilizar y llamar al método DrawImage del objeto Graphics. La imagen se pintará sobre la superficie de dibujo representada por la clase Graphics. Los archivos de imagen se pueden crear y modificar mediante el Editor de imágenes en tiempo de diseño para representarlos posteriormente con la interfaz GDI+ en tiempo de ejecución. Para obtener más información, vea Editor de imágenes.

Para representar una imagen con GDI+

  1. Cree un objeto que represente a la imagen que desea mostrar. Este objeto debe ser miembro de una clase que herede de Image, como Bitmap o Metafile. A continuación se muestra un ejemplo:

    Visual Basic
    ' Uses the System.Environment.GetFolderPath to get the path to the 
    ' current user's MyPictures folder.
    Dim myBitmap as New Bitmap _
       (System.Environment.GetFolderPath _
          (System.Environment.SpecialFolder.MyPictures))
    

    C#
    // Uses the System.Environment.GetFolderPath to get the path to the 
    // current user's MyPictures folder.
    Bitmap myBitmap = new Bitmap
       (System.Environment.GetFolderPath
          (System.Environment.SpecialFolder.MyPictures));
    

    Visual C++
    // Uses the System.Environment.GetFolderPath to get the path to the 
    // current user's MyPictures folder.
    Bitmap^ myBitmap = gcnew Bitmap
       (System::Environment::GetFolderPath
          (System::Environment::SpecialFolder::MyPictures));
  2. Cree un objeto Graphics que represente la superficie de dibujo que desea usar. Para obtener más información, vea Cómo: Crear objetos Graphics para dibujar.

    Visual Basic
    ' Creates a Graphics object that represents the drawing surface of 
    ' Button1.
    Dim g as Graphics = Button1.CreateGraphics
    

    C#
    // Creates a Graphics object that represents the drawing surface of 
    // Button1.
    Graphics g = Button1.CreateGraphics();
    

    Visual C++
    // Creates a Graphics object that represents the drawing surface of 
    // Button1.
    Graphics^ g = button1->CreateGraphics();
  3. Llame al método DrawImage del objeto Graphics para representar la imagen. Deberá especificar la imagen que desea que se dibuje y las coordenadas en las que se debe dibujar.

    Visual Basic
    g.DrawImage(myBitmap, 1, 1)
    

    C#
    g.DrawImage(myBitmap, 1, 1);
    

    Visual C++
    g->DrawImage(myBitmap, 1, 1);
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2009 Microsoft Corporation. Reservados todos los derechos. Temas legales | Marcas Registradas | Declaración de privacidad
Page view tracker