RenderTargetBitmap 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 Visual 对象转换为位图。
public ref class RenderTargetBitmap sealed : System::Windows::Media::Imaging::BitmapSource
public sealed class RenderTargetBitmap : System.Windows.Media.Imaging.BitmapSource
type RenderTargetBitmap = class
inherit BitmapSource
Public NotInheritable Class RenderTargetBitmap
Inherits BitmapSource
- 继承
-
RenderTargetBitmap
示例
以下示例演示如何用于 RenderTargetBitmap 将文本呈现为图像。
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;
}
}
}
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
End Class
End Namespace 'ImagingSnippetGallery
构造函数
| 名称 | 说明 |
|---|---|
| RenderTargetBitmap(Int32, Int32, Double, Double, PixelFormat) |
初始化具有指定参数的 RenderTargetBitmap 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| CanFreeze |
获取一个值,该值指示是否可以使对象不可修改。 (继承自 Freezable) |
| DependencyObjectType |
获取包装 DependencyObjectType 此实例的 CLR 类型。 (继承自 DependencyObject) |
| Dispatcher |
获取与此DispatcherDispatcherObject关联的值。 (继承自 DispatcherObject) |
| DpiX |
获取图像的水平点/英寸(dpi)。 (继承自 BitmapSource) |
| DpiY |
获取图像的垂直点/英寸(dpi)。 (继承自 BitmapSource) |
| Format |
获取位图数据的本机 PixelFormat 。 (继承自 BitmapSource) |
| HasAnimatedProperties |
获取一个值,该值指示一个或多个 AnimationClock 对象是否与此对象的依赖属性中的任何一个相关联。 (继承自 Animatable) |
| Height |
获取与设备无关的单位(每单位 1/96 英寸)的源位图的高度。 (继承自 BitmapSource) |
| IsDownloading |
获取一个值,该值指示内容当前是否 BitmapSource 正在下载。 (继承自 BitmapSource) |
| IsFrozen |
获取一个值,该值指示对象当前是否可修改。 (继承自 Freezable) |
| IsSealed |
获取一个值,该值指示此实例当前是否密封(只读)。 (继承自 DependencyObject) |
| Metadata |
获取与此位图图像关联的元数据。 (继承自 BitmapSource) |
| Palette |
获取位图的调色板(如果指定)。 (继承自 BitmapSource) |
| PixelHeight |
获取位图的高度(以像素为单位)。 (继承自 BitmapSource) |
| PixelWidth |
获取位图的宽度(以像素为单位)。 (继承自 BitmapSource) |
| Width |
获取独立于设备的位图的宽度(每单位 1/96 英寸)。 (继承自 BitmapSource) |
方法
活动
| 名称 | 说明 |
|---|---|
| Changed |
修改它包含的对象时 Freezable 发生。 (继承自 Freezable) |
| DecodeFailed |
由于映像标头损坏,映像无法加载时发生。 (继承自 BitmapSource) |
| DownloadCompleted |
完全下载位图内容时发生。 (继承自 BitmapSource) |
| DownloadFailed |
当位图内容无法下载时发生。 (继承自 BitmapSource) |
| DownloadProgress |
当位图内容的下载进度发生更改时发生。 (继承自 BitmapSource) |
显式接口实现
| 名称 | 说明 |
|---|---|
| IFormattable.ToString(String, IFormatProvider) |
使用指定格式设置当前实例的值的格式。 (继承自 ImageSource) |