本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap类的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap类的具体用法?C# RenderTargetBitmap怎么用?C# RenderTargetBitmap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RenderTargetBitmap类属于System.Windows.Media.Imaging命名空间,在下文中一共展示了RenderTargetBitmap类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderTargetBitmapExample
//引入命名空间
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;
}
}
}