Files
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

1.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Encode a Visual to an Image File 03/30/2017
csharp
vb
image files [WPF], encoding from visuals
encoding image formats [WPF]
visuals [WPF], encoding to an image file
2036385b-ea47-4d54-8027-5797f52c8149

How to: Encode a Visual to an Image File

This example demonstrates how to encode a xref:System.Windows.Media.Visual object into an image file using a xref:System.Windows.Media.Imaging.RenderTargetBitmap and a xref:System.Windows.Media.Imaging.PngBitmapEncoder.

Example

The xref:System.Windows.Media.DrawingVisual is created using a xref:System.Windows.Media.Imaging.BitmapImage and xref:System.Windows.Media.FormattedText which is rendered to a xref:System.Windows.Media.Imaging.RenderTargetBitmap. The rendered bitmap is then used to create a xref:System.Windows.Media.Imaging.BitmapFrame which is added to the xref:System.Windows.Media.Imaging.PngBitmapEncoder to create a new Portable Network Graphics (PNG) file.

[!code-csharpImagingSnippetGallery_procedural_snip#RTBEncodeInline1] [!code-vbImagingSnippetGallery_procedural_snip#RTBEncodeInline1]

A xref:System.Windows.Media.Imaging.PngBitmapEncoder was used in this example but any of the derived xref:System.Windows.Media.Imaging.BitmapEncoder objects could have been used to create the image file.

See also