* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
3.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Render Images with GDI+ | 03/30/2017 |
|
|
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 xref:System.Drawing.Image class (such as xref:System.Drawing.Bitmap), creating a xref:System.Drawing.Graphics object that refers to the drawing surface you want to use, and calling the xref:System.Drawing.Graphics.DrawImage%2A method of the xref:System.Drawing.Graphics 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.
To render an image with GDI+
-
Create an object representing the image you want to display. This object must be a member of a class that inherits from xref:System.Drawing.Image, such as xref:System.Drawing.Bitmap or xref:System.Drawing.Imaging.Metafile. An example is shown:
' 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))// 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));// 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)); -
Create a xref:System.Drawing.Graphics object that represents the drawing surface you want to use. For more information, see How to: Create Graphics Objects for Drawing.
' Creates a Graphics object that represents the drawing surface of ' Button1. Dim g as Graphics = Button1.CreateGraphics// Creates a Graphics object that represents the drawing surface of // Button1. Graphics g = Button1.CreateGraphics();// Creates a Graphics object that represents the drawing surface of // Button1. Graphics^ g = button1->CreateGraphics(); -
Call the xref:System.Drawing.Graphics.DrawImage%2A 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.
g.DrawImage(myBitmap, 1, 1)g.DrawImage(myBitmap, 1, 1);g->DrawImage(myBitmap, 1, 1);