The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
RenderTargetBitmap Class
Visual Studio 2008
Converts a Visual object into a bitmap.
Assembly: PresentationCore (in PresentationCore.dll)
The following example shows how to use RenderTargetBitmap to render text as an image.
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Globalization; namespace SDKSample { public partial class RenderTargetBitmapExample : Page { public RenderTargetBitmapExample() { Image myImage = new Image(); FormattedText text = new FormattedText("ABC", new CultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface(this.FontFamily, FontStyles.Normal, FontWeights.Normal, new FontStretch()), this.FontSize, this.Foreground); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawText(text, new Point(2, 2)); drawingContext.Close(); RenderTargetBitmap bmp = new RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32); bmp.Render(drawingVisual); myImage.Source = bmp; // Add Image to the UI StackPanel myStackPanel = new StackPanel(); myStackPanel.Children.Add(myImage); this.Content = myStackPanel; } } }
More Code
| How to: Create a Bitmap from a Visual | This example shows how you can create a bitmap from a Visual. A DrawingVisual is rendered with FormattedText. The Visual is then rendered to the RenderTargetBitmap creating a bitmap of the given text. |
| How to: Encode a Visual to an Image File | This example demonstrates how to encode a Visual object into an image file using a RenderTargetBitmapand a PngBitmapEncoder. |
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Community Additions
Show: