--- title: "How to: Encode a Visual to an Image File" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "image files [WPF], encoding from visuals" - "encoding image formats [WPF]" - "visuals [WPF], encoding to an image file" ms.assetid: 2036385b-ea47-4d54-8027-5797f52c8149 --- # How to: Encode a Visual to an Image File This example demonstrates how to encode a object into an image file using a and a . ## Example The is created using a and which is rendered to a . The rendered bitmap is then used to create a which is added to the to create a new Portable Network Graphics (PNG) file. [!code-csharp[ImagingSnippetGallery_procedural_snip#RTBEncodeInline1](~/samples/snippets/csharp/VS_Snippets_Wpf/ImagingSnippetGallery_procedural_snip/CSharp/RenderTargetBitmapExample_Encode.cs#rtbencodeinline1)] [!code-vb[ImagingSnippetGallery_procedural_snip#RTBEncodeInline1](~/samples/snippets/visualbasic/VS_Snippets_Wpf/ImagingSnippetGallery_procedural_snip/VB/RenderTargetBitmapExample_Encode.vb#rtbencodeinline1)] A was used in this example but any of the derived objects could have been used to create the image file. ## See also - - [Imaging Overview](imaging-overview.md) - [Drawing Objects Overview](drawing-objects-overview.md) - [Using DrawingVisual Objects](using-drawingvisual-objects.md)