Graphics::FromImage, méthode (gdiplusgraphics.h)

La méthode Graphics::FromImage crée un objet Graphics associé à un objet Image spécifié.

Syntaxe

Graphics * FromImage(
  [in] Image *image
);

Paramètres

[in] image

Type : Image*

Pointeur vers un objet Image qui sera associé au nouvel objet Graphics .

Valeur retournée

Type : Graphiques*

Cette méthode retourne un pointeur vers le nouvel objet Graphics .

Notes

Cette méthode échoue si l’objet Image est basé sur un métafichier ouvert pour la lecture. Les constructeurs Image::Image(filename, useEmbeddedColorManagement) et Metafile::Metafile(filename) ouvrent un métafichier pour la lecture. Pour ouvrir un métafichier pour l’enregistrement, utilisez un constructeur Metafile qui reçoit un handle de contexte d’appareil.

Cette méthode échoue également si l’image a l’un des formats de pixels suivants :

  • PixelFormatUndefined
  • PixelFormatDontCare
  • PixelFormat1bppIndexed
  • PixelFormat4bppIndexed
  • PixelFormat8bppIndexed
  • PixelFormat16bppGrayScale
  • PixelFormat16bppARGB1555

Exemples

L’exemple suivant appelle la méthode Graphics::FromImage pour créer un objet Graphics associé à un objet Image . L’appel à Graphics::FillEllipse ne peint pas sur l’appareil d’affichage ; au lieu de cela, il modifie l’image bitmap de l’objet Image . L’appel à Graphics::D rawImage affiche l’image bitmap modifiée.

VOID Example_FromImage(HDC hdc)
{
   Graphics graphics(hdc);

   // Create an Image object from a PNG file.
   Image image(L"Mosaic.png");

   // Create a Graphics object that is associated with the image.
   Graphics* imageGraphics = Graphics::FromImage(&image);
   
   // Alter the image.
   SolidBrush brush(Color(255, 0, 0, 255));
   imageGraphics->FillEllipse(&brush, 10, 40, 100, 50);

   // Draw the altered image.
   graphics.DrawImage(&image, 30, 20);
   
   delete imageGraphics;
}

Configuration requise

   
Client minimal pris en charge Windows XP, Windows 2000 Professionnel [applications de bureau uniquement]
Serveur minimal pris en charge Windows 2000 Server [applications de bureau uniquement]
Plateforme cible Windows
En-tête gdiplusgraphics.h (inclure Gdiplus.h)
Bibliothèque Gdiplus.lib
DLL Gdiplus.dll

Voir aussi

Changements dans le modèle de programmation

Méthodes FromHDC

Graphismes

Constructeurs graphiques

Graphiques::FromHWND

Graphiques::GetHDC

Utilisation d’images, de bitmaps et de métafichiers