RenderTargetBitmap Class Home
This page is specific to:.NET Framework Version:3.03.5Silverlight 34.0
.NET Framework Class Library
RenderTargetBitmap Class

Converts a Visual object into a bitmap.

Namespace:  System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax

'Usage

Dim instance As RenderTargetBitmap

'Declaration

Public NotInheritable Class RenderTargetBitmap _
    Inherits BitmapSource
You cannot directly create an instance of this class in XAML.
Examples

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



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.
Inheritance Hierarchy

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows..::.Freezable
        System.Windows.Media.Animation..::.Animatable
          System.Windows.Media..::.ImageSource
            System.Windows.Media.Imaging..::.BitmapSource
              System.Windows.Media.Imaging..::.RenderTargetBitmap
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

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.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View