public static Export ( OxyPlot.PlotModel model, string fileName, int width, int height, |
||
model | OxyPlot.PlotModel | |
fileName | string | |
width | int | |
height | int | |
background | ||
Результат | void |
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);
}
}
}
private void buttonSavePNG_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PNG Files (*.png)|*.png"; saveFileDialog1.FilterIndex = 1; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { MousePlot.Export(this.plot1.Model, saveFileDialog1.FileName, 800, 600); } }