Delphin Posted January 12, 2008 Report Share Posted January 12, 2008 You can use a such code, hope it will help someone. using System;using System.IO;using System.Drawing;using System.Drawing.Imaging;using ChartFX.WinForms;namespace ChartFxTools{ public enum eImageFormat { Jpeg, Gif, Png } public static class CChartFxTools { public static void Save(Chart pChart, string pImagePath, eImageFormat pImageFormat) { string bmpFilePath = Path.ChangeExtension(pImagePath, ".bmp"); pChart.Export(FileFormat.Bitmap, bmpFilePath); Convert(bmpFilePath, pImageFormat); } private static void Convert(string pBmpFile, eImageFormat pImageFormat) { if (pBmpFile == null) { throw new ArgumentNullException("The BmpFile parameter cannot be null"); } if (!File.Exists(pBmpFile)) { throw new FileNotFoundException("Cannot find the " + pBmpFile + " file"); } Bitmap bitmap = null; ImageFormat imageFormat = GetImageFormat(pImageFormat); try { bitmap = new Bitmap(pBmpFile); string newFilePath = Path.ChangeExtension(pBmpFile, pImageFormat.ToString().ToLower()); bitmap.Save(newFilePath, imageFormat); } catch (System.Exception) { throw; } finally { if (bitmap != null) { bitmap.Dispose(); bitmap = null; } try { File.Delete(pBmpFile); } catch (System.Exception) { } } } private static ImageFormat GetImageFormat(eImageFormat pImageFormat) { switch (pImageFormat) { case eImageFormat.Jpeg: return ImageFormat.Jpeg; case eImageFormat.Gif: return ImageFormat.Gif; case eImageFormat.Png: return ImageFormat.Png; } return ImageFormat.Png; } }} To use it: using ChartFxTools; Chart chart = new Chart()...CChartFxTools.Save(chart, @"C:\myChartImage.png", eImageFormat.Png);...Note : do not forget to add all required references to use this source. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.