Updated: November 2007
Converts a Visual object into a bitmap.
Public NotInheritable Class RenderTargetBitmap _ Inherits BitmapSource
Dim instance As RenderTargetBitmap
public sealed class RenderTargetBitmap : BitmapSource
public ref class RenderTargetBitmap sealed : public BitmapSource
public final class RenderTargetBitmap extends BitmapSource
You cannot directly create an instance of this class in XAML.
The following example shows how to use RenderTargetBitmap to render text as an image.
Imports System Imports System.Windows Imports System.Windows.Controls Imports System.Windows.Media Imports System.Windows.Media.Imaging Imports System.Globalization Namespace SDKSample Class RenderTargetBitmapExample Inherits Page Public Sub New() Dim myImage As New Image() Dim [text] As New FormattedText("ABC", New CultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, New Typeface(Me.FontFamily, FontStyles.Normal, FontWeights.Normal, New FontStretch()), Me.FontSize, Me.Foreground) Dim drawingVisual As New DrawingVisual() Dim drawingContext As DrawingContext = drawingVisual.RenderOpen() drawingContext.DrawText([text], New System.Windows.Point(2, 2)) drawingContext.Close() Dim bmp As New RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32) bmp.Render(drawingVisual) myImage.Source = bmp ' Add Image to the UI Dim myStackPanel As New StackPanel() myStackPanel.Children.Add(myImage) Me.Content = myStackPanel End Sub 'New End Class 'RenderTargetBitmapExample End Namespace 'ImagingSnippetGallery
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; } } }
Windows Vista