--- title: "How to: Render Images with GDI+" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "images [Windows Forms], creating" - "GDI+, rendering existing images" ms.assetid: c128b79a-3e31-47d8-9e66-3470f570a056 --- # How to: Render Images with GDI+ You can use GDI+ to render images that exist as files in your applications. You do this by creating a new object of an class (such as ), creating a object that refers to the drawing surface you want to use, and calling the method of the object. The image will be painted onto the drawing surface represented by the graphics class. You can use the Image Editor to create and edit image files at design time, and render them with GDI+ at run time. For more information, see [Image Editor for Icons](/cpp/windows/image-editor-for-icons). ### To render an image with GDI+ 1. Create an object representing the image you want to display. This object must be a member of a class that inherits from , such as or . An example is shown: ```vb ' 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)) ``` ```csharp // 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)); ``` ```cpp // 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. Create a object that represents the drawing surface you want to use. For more information, see [How to: Create Graphics Objects for Drawing](how-to-create-graphics-objects-for-drawing.md). ```vb ' Creates a Graphics object that represents the drawing surface of ' Button1. Dim g as Graphics = Button1.CreateGraphics ``` ```csharp // Creates a Graphics object that represents the drawing surface of // Button1. Graphics g = Button1.CreateGraphics(); ``` ```cpp // Creates a Graphics object that represents the drawing surface of // Button1. Graphics^ g = button1->CreateGraphics(); ``` 3. Call the of your graphics object to render the image. You must specify both the image to be drawn, and the coordinates where it is to be drawn. ```vb g.DrawImage(myBitmap, 1, 1) ``` ```csharp g.DrawImage(myBitmap, 1, 1); ``` ```cpp g->DrawImage(myBitmap, 1, 1); ``` ## See also - [Getting Started with Graphics Programming](getting-started-with-graphics-programming.md) - [How to: Create Graphics Objects for Drawing](how-to-create-graphics-objects-for-drawing.md) - [Pens, Lines, and Rectangles in GDI+](pens-lines-and-rectangles-in-gdi.md) - [How to: Draw Text on a Windows Form](how-to-draw-text-on-a-windows-form.md) - [Graphics and Drawing in Windows Forms](graphics-and-drawing-in-windows-forms.md) - [Drawing Lines or Closed Figures](/cpp/windows/drawing-lines-or-closed-figures-image-editor-for-icons) - [Image Editor for Icons](/cpp/windows/image-editor-for-icons)