本文整理汇总了C#中PlotModel.Render方法的典型用法代码示例。如果您正苦于以下问题:C# PlotModel.Render方法的具体用法?C# PlotModel.Render怎么用?C# PlotModel.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlotModel
的用法示例。
在下文中一共展示了PlotModel.Render方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportToString
/// <summary>
/// Export the specified plot model to an xaml string.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="background">The background.</param>
/// <returns>A xaml string.</returns>
public static string ExportToString(PlotModel model, double width, double height, OxyColor background = null)
{
var g = new Grid();
if (background != null)
{
g.Background = background.ToBrush();
}
var c = new Canvas();
g.Children.Add(c);
var size = new Size(width, height);
g.Measure(size);
g.Arrange(new Rect(0, 0, width, height));
g.UpdateLayout();
var rc = new ShapesRenderContext(c) { UseStreamGeometry = false };
model.Update();
model.Render(rc, width, height);
var sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
var xw = XmlWriter.Create(sw, new XmlWriterSettings { Indent = true });
XamlWriter.Save(c, xw);
}
return sb.ToString();
}
示例2: Export
/// <summary>
/// Exports the specified model to a stream.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <param name="s">
/// The stream.
/// </param>
/// <param name="width">
/// The width (points).
/// </param>
/// <param name="height">
/// The height (points).
/// </param>
public static void Export(PlotModel model, Stream s, double width, double height)
{
using (var rc = new PdfRenderContext(width, height, model.Background))
{
model.Update();
model.Render(rc, width, height);
rc.Save(s);
}
}
示例3: Export
/// <summary>
/// The export.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <param name="fileName">
/// The file name.
/// </param>
/// <param name="width">
/// The width.
/// </param>
/// <param name="height">
/// The height.
/// </param>
/// <param name="background">
/// The background.
/// </param>
public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null)
{
using (var bm = new Bitmap(width, height))
{
using (Graphics g = Graphics.FromImage(bm))
{
if (background != null)
{
g.FillRectangle(background, 0, 0, width, height);
}
var rc = new GraphicsRenderContext { RendersToScreen = false };
rc.SetGraphicsTarget(g);
model.Update();
model.Render(rc, width, height);
bm.Save(fileName, ImageFormat.Png);
}
}
}
示例4: Export
/// <summary>
/// Exports the specified plot model to an xps file.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="fileName">The file name.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="background">The background color.</param>
public static void Export(
PlotModel model, string fileName, double width, double height, OxyColor background = null)
{
using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
{
using (var doc = new XpsDocument(xpsPackage))
{
var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
var rc = new ShapesRenderContext(canvas);
model.Update();
model.Render(rc, width, height);
canvas.UpdateLayout();
var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
xpsdw.Write(canvas);
}
}
}
示例5: ExportToBitmap
/// <summary>
/// Exports the specified plot model to a bitmap.
/// </summary>
/// <param name="model">The plot model.</param>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="background">The background.</param>
/// <param name="dpi">The resolution.</param>
/// <returns>A bitmap.</returns>
public static BitmapSource ExportToBitmap(PlotModel model, int width, int height, OxyColor background = null, int dpi = 96)
{
var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
var rc = new ShapesRenderContext(canvas) { RendersToScreen = false };
model.Update();
model.Render(rc, width, height);
canvas.UpdateLayout();
var bmp = new RenderTargetBitmap(width, height, dpi, dpi, PixelFormats.Pbgra32);
bmp.Render(canvas);
return bmp;
// alternative implementation:
// http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx
// var dv = new DrawingVisual();
// using (var ctx = dv.RenderOpen())
// {
// var vb = new VisualBrush(canvas);
// ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
// }
// bmp.Render(dv);
}
示例6: Print
/// <summary>
/// Prints the specified plot model.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="width">The width (using the actual media width if not specified).</param>
/// <param name="height">The height (using the actual media height if not specified).</param>
public static void Print(PlotModel model, double width = double.NaN, double height = double.NaN)
{
PrintDocumentImageableArea area = null;
var xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(ref area);
if (xpsDocumentWriter != null)
{
if (double.IsNaN(width))
{
width = area.MediaSizeWidth;
}
if (double.IsNaN(height))
{
height = area.MediaSizeHeight;
}
var canvas = new Canvas { Width = width, Height = height };
canvas.Measure(new Size(width, height));
canvas.Arrange(new Rect(0, 0, width, height));
var rc = new ShapesRenderContext(canvas);
model.Update();
model.Render(rc, width, height);
canvas.UpdateLayout();
xpsDocumentWriter.Write(canvas);
}
}
示例7: Save
public static void Save(PlotModel model, Stream s, double width, double height)
{
var svgrc = new PdfRenderContext(width, height);
model.Render(svgrc);
svgrc.Save(s);
}