本文整理汇总了C#中System.Windows.Controls.Canvas.ToImage方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.ToImage方法的具体用法?C# Canvas.ToImage怎么用?C# Canvas.ToImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.Canvas
的用法示例。
在下文中一共展示了Canvas.ToImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Export
/// <summary>
/// Exports the specified plot model to a stream.
/// </summary>
/// <param name="model">The plot model.</param>
/// <param name="stream">The stream to write to.</param>
/// <param name="width">The width of the export image.</param>
/// <param name="height">The height of the exported image.</param>
/// <param name="background">The background.</param>
public static void Export(IPlotModel model, Stream stream, double width, double height, OxyColor background)
{
var canvas = new Canvas { Width = width, Height = height };
if (background.IsVisible())
{
canvas.Background = background.ToBrush();
}
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
var rc = new SilverlightRenderContext(canvas);
model.Update(true);
model.Render(rc, width, height);
canvas.UpdateLayout();
var image = canvas.ToImage();
image.WriteToStream(stream);
}
示例2: SaveToImage
void SaveToImage(Canvas canvas, SaveFileDialog dialog, IImageEncoder encoder)
{
using (var stream = dialog.OpenFile())
{
var image = canvas.ToImage();
encoder.Encode(image, stream);
}
}