* 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
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 |
|
|
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.