SharpLibDisplay update and priority support.
1 // --------------------------------------------------------------------------------------------------------------------
2 // <copyright file="PngExporter.cs" company="OxyPlot">
3 // The MIT License (MIT)
5 // Copyright (c) 2012 Oystein Bjorke
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be included
16 // in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 // --------------------------------------------------------------------------------------------------------------------
30 namespace OxyPlot.WindowsForms
33 using System.Drawing.Imaging;
35 using OxyPlot.WindowsForms;
40 public static class PngExporter
45 /// <param name="model">
48 /// <param name="fileName">
51 /// <param name="width">
54 /// <param name="height">
57 /// <param name="background">
60 public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null)
62 using (var bm = new Bitmap(width, height))
64 using (Graphics g = Graphics.FromImage(bm))
66 if (background != null)
68 g.FillRectangle(background, 0, 0, width, height);
71 var rc = new GraphicsRenderContext { RendersToScreen = false };
72 rc.SetGraphicsTarget(g);
74 model.Render(rc, width, height);
75 bm.Save(fileName, ImageFormat.Png);