/// <summary> /// Gets an image for the current GraphPane, scaled to the specified size and resolution. /// </summary> /// <param name="width">The scaled width of the bitmap in pixels</param> /// <param name="height">The scaled height of the bitmap in pixels</param> /// <param name="dpi">The resolution of the bitmap, in dots per inch</param> /// <seealso cref="GetImage()"/> /// <seealso cref="Bitmap"/> public Bitmap GetImage(int width, int height, float dpi) { Bitmap bitmap = new Bitmap(width, height); bitmap.SetResolution(dpi, dpi); using (Graphics bitmapGraphics = Graphics.FromImage(bitmap)) { //bitmapGraphics.SmoothingMode = SmoothingMode.AntiAlias; // Clone the GraphPane so we don't mess up the minPix and maxPix values or // the rect/ChartRect calculations of the original //PaneBase tempPane = (PaneBase) ((ICloneable)this).Clone(); // This is actually a shallow clone, so we don't duplicate all the data, curveLists, etc. PaneBase tempPane = this.ShallowClone(); tempPane.ReSize(bitmapGraphics, new RectangleF(0, 0, width, height)); //tempPane.AxisChange( bitmapGraphics ); tempPane.Draw(bitmapGraphics); //this.Draw( bitmapGraphics ); this.ReSize(bitmapGraphics, this.Rect); //bitmapGraphics.Dispose(); } return(bitmap); }
/// <summary> /// Gets an image for the current GraphPane, scaled to the specified size and resolution. /// </summary> /// <param name="width">The scaled width of the bitmap in pixels</param> /// <param name="height">The scaled height of the bitmap in pixels</param> /// <param name="dpi">The resolution of the bitmap, in dots per inch</param> /// <seealso cref="GetImage()"/> /// <seealso cref="Bitmap"/> public Bitmap GetImage(int width, int height, float dpi) { var bitmap = new Bitmap(width, height); bitmap.SetResolution(dpi, dpi); using (Graphics bitmapGraphics = Graphics.FromImage(bitmap)) { //bitmapGraphics.SmoothingMode = SmoothingMode.AntiAlias; // This is actually a shallow clone, so we don't duplicate all the data, curveLists, etc. PaneBase tempPane = ShallowClone(); // Clone the Chart object for GraphPanes so we don't mess up the minPix and maxPix values or // the rect/ChartRect calculations of the original var saveRect = new RectangleF(); if (this is GraphPane) { saveRect = (this as GraphPane).Chart.Rect; } tempPane.ReSize(bitmapGraphics, new RectangleF(0, 0, width, height)); tempPane.Draw(bitmapGraphics); if (this is GraphPane) { var gPane = this as GraphPane; gPane.Chart.Rect = saveRect; gPane.XAxis.Scale.SetupScaleData(gPane, gPane.XAxis); foreach (Axis axis in gPane.YAxisList) { axis.Scale.SetupScaleData(gPane, axis); } foreach (Axis axis in gPane.Y2AxisList) { axis.Scale.SetupScaleData(gPane, axis); } } ReSize(bitmapGraphics, Rect); } return(bitmap); }
/// <summary> /// Gets an image for the current GraphPane, scaled to the specified size and resolution. /// </summary> /// <param name="width">The scaled width of the bitmap in pixels</param> /// <param name="height">The scaled height of the bitmap in pixels</param> /// <param name="dpi">The resolution of the bitmap, in dots per inch</param> /// <seealso cref="Image"/> /// <seealso cref="Bitmap"/> public Bitmap ScaledImage(int width, int height, float dpi) { Bitmap bitmap = new Bitmap(width, height); bitmap.SetResolution(dpi, dpi); Graphics bitmapGraphics = Graphics.FromImage(bitmap); // Clone the GraphPane so we don't mess up the minPix and maxPix values or // the paneRect/axisRect calculations of the original PaneBase tempPane = (PaneBase)this.Clone(); tempPane.ReSize(bitmapGraphics, new RectangleF(0, 0, width, height)); //tempPane.AxisChange( bitmapGraphics ); tempPane.Draw(bitmapGraphics); //this.Draw( bitmapGraphics ); bitmapGraphics.Dispose(); return(bitmap); }