moel@391: // --------------------------------------------------------------------------------------------------------------------
moel@391: //
moel@391: // The MIT License (MIT)
moel@391: //
moel@391: // Copyright (c) 2012 Oystein Bjorke
moel@391: //
moel@391: // Permission is hereby granted, free of charge, to any person obtaining a
moel@391: // copy of this software and associated documentation files (the
moel@391: // "Software"), to deal in the Software without restriction, including
moel@391: // without limitation the rights to use, copy, modify, merge, publish,
moel@391: // distribute, sublicense, and/or sell copies of the Software, and to
moel@391: // permit persons to whom the Software is furnished to do so, subject to
moel@391: // the following conditions:
moel@391: //
moel@391: // The above copyright notice and this permission notice shall be included
moel@391: // in all copies or substantial portions of the Software.
moel@391: //
moel@391: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
moel@391: // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
moel@391: // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
moel@391: // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
moel@391: // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
moel@391: // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
moel@391: // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
moel@391: //
moel@391: //
moel@391: // The png exporter.
moel@391: //
moel@391: // --------------------------------------------------------------------------------------------------------------------
moel@391: namespace OxyPlot.WindowsForms
moel@391: {
moel@391: using System.Drawing;
moel@391: using System.Drawing.Imaging;
moel@391:
moel@391: using OxyPlot.WindowsForms;
moel@391:
moel@391: ///
moel@391: /// The png exporter.
moel@391: ///
moel@391: public static class PngExporter
moel@391: {
moel@391: ///
moel@391: /// The export.
moel@391: ///
moel@391: ///
moel@391: /// The model.
moel@391: ///
moel@391: ///
moel@391: /// The file name.
moel@391: ///
moel@391: ///
moel@391: /// The width.
moel@391: ///
moel@391: ///
moel@391: /// The height.
moel@391: ///
moel@391: ///
moel@391: /// The background.
moel@391: ///
moel@391: public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null)
moel@391: {
moel@391: using (var bm = new Bitmap(width, height))
moel@391: {
moel@391: using (Graphics g = Graphics.FromImage(bm))
moel@391: {
moel@391: if (background != null)
moel@391: {
moel@391: g.FillRectangle(background, 0, 0, width, height);
moel@391: }
moel@391:
moel@391: var rc = new GraphicsRenderContext { RendersToScreen = false };
moel@391: rc.SetGraphicsTarget(g);
moel@391: model.Update();
moel@391: model.Render(rc, width, height);
moel@391: bm.Save(fileName, ImageFormat.Png);
moel@391: }
moel@391: }
moel@391: }
moel@391:
moel@391: }
moel@391: }