Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/drawing-positioning-and-cloning-images-in-gdi.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* 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
2020-09-01 16:26:21 -07:00

3.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Drawing, Positioning, and Cloning Images in GDI+ 03/30/2017
csharp
vb
raster images [Windows Forms]
images [Windows Forms], positioning
drawing [Windows Forms], images
drawing [Windows Forms], raster images
images [Windows Forms], cloning
images [Windows Forms], drawing
GDI+, drawing images
GDI+, cloning images
GDI+, positioning images
09f0c07a-19c0-43b4-90a2-862a10545ce8

Drawing, Positioning, and Cloning Images in GDI+

You can use the xref:System.Drawing.Bitmap class to load and display raster images, and you can use the xref:System.Drawing.Imaging.Metafile class to load and display vector images. The xref:System.Drawing.Bitmap and xref:System.Drawing.Imaging.Metafile classes inherit from the xref:System.Drawing.Image class. To display a vector image, you need an instance of the xref:System.Drawing.Graphics class and a xref:System.Drawing.Imaging.Metafile. To display a raster image, you need an instance of the xref:System.Drawing.Graphics class and a xref:System.Drawing.Bitmap. The instance of the xref:System.Drawing.Graphics class provides the xref:System.Drawing.Graphics.DrawImage%2A method, which receives the xref:System.Drawing.Imaging.Metafile or xref:System.Drawing.Bitmap as an argument.

File Types and Cloning

The following code example shows how to construct a xref:System.Drawing.Bitmap from the file Climber.jpg and displays the bitmap. The destination point for the upper-left corner of the image, (10, 10), is specified in the second and third parameters.

[!code-csharpSystem.Drawing.ImagesBitmapsMetafiles#11] [!code-vbSystem.Drawing.ImagesBitmapsMetafiles#11]

The following illustration shows the image.

Image Sample

You can construct xref:System.Drawing.Bitmap objects from a variety of graphics file formats: BMP, GIF, JPEG, EXIF, PNG, TIFF, and ICON.

The following code example shows how to construct xref:System.Drawing.Bitmap objects from a variety of file types and then displays the bitmaps.

[!code-csharpSystem.Drawing.ImagesBitmapsMetafiles#12] [!code-vbSystem.Drawing.ImagesBitmapsMetafiles#12]

The xref:System.Drawing.Bitmap class provides a xref:System.Drawing.Bitmap.Clone%2A method that you can use to make a copy of an existing xref:System.Drawing.Bitmap. The xref:System.Drawing.Bitmap.Clone%2A method has a source rectangle parameter that you can use to specify the portion of the original bitmap that you want to copy. The following code example shows how to create a xref:System.Drawing.Bitmap by cloning the top half of an existing xref:System.Drawing.Bitmap. Then both images are drawn.

[!code-csharpSystem.Drawing.ImagesBitmapsMetafiles#13] [!code-vbSystem.Drawing.ImagesBitmapsMetafiles#13]

The following illustration shows the two images.

Cropping

See also