将chart柱状图保存为图片格式

带有弹出的保存页面,可以设置图片的名字,选择图片保存的格式

private void ExportPicture(string fileName)
        {
            string saveFileName = "";
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.FileName = fileName;
            //saveDialog.ShowDialog();
            saveFileName = saveDialog.FileName;

            saveDialog.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|SVG (*.svg)|*.svg|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif";
            saveDialog.FilterIndex = 2;
            saveDialog.RestoreDirectory = true;

            // Set image file format
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                ChartImageFormat format = ChartImageFormat.Bmp;

                if (saveDialog.FileName.EndsWith("bmp"))
                {
                    format = ChartImageFormat.Bmp;
                }
                else if (saveDialog.FileName.EndsWith("jpg"))
                {
                    format = ChartImageFormat.Jpeg;
                }
                else if (saveDialog.FileName.EndsWith("emf"))
                {
                    format = ChartImageFormat.Emf;
                }
                else if (saveDialog.FileName.EndsWith("gif"))
                {
                    format = ChartImageFormat.Gif;
                }
                else if (saveDialog.FileName.EndsWith("png"))
                {
                    format = ChartImageFormat.Png;
                }
                else if (saveDialog.FileName.EndsWith("tif"))
                {
                    format = ChartImageFormat.Tiff;
                }

                // Save image
                chart1.SaveImage(saveDialog.FileName, format);
            }
        }

你可能感兴趣的:(chart)