我試圖導出MSChart的圖像。從基於MSChart的應用程序導出引發矢量格式的例外
我發現了精彩的功能
[System.Windows.Forms.DataVisualization.Charting.Chart.SaveImage][1]
但是我遇到的的imageformat參數的幾個問題。具體而言,我希望用戶能夠以任何格式保存圖像,其格式爲WIC編碼器。爲此,我得到了圖像編解碼器的列表,並將它們全部提供給用戶。
因此,當用戶選擇他們的文件時,我抓住擴展名並在列表中找到與擴展名匹配的編解碼器。然後,我創建相關的imageformat如下:
ImageFormat imgFmt = new ImageFormat(codec.FormatID);
我然後調用下面的圖表導出:
exportChart.SaveImage(mSaveFileDialog.FileName, imgFmt);
然而,這會拋出一個異常,如果我選擇的EMF或WMF,如下所示:
A first chance exception of type 'System.ArgumentNullException' occurred in System.Drawing.dll
An unhandled exception of type 'System.ArgumentNullException' occurred in System.Drawing.dll
Additional information: Value cannot be null.
最奇怪的事情是,如果我創造我的圖片格式如下:
ImageFormat imgFmt = ImageFormat.Emf;
然後它寫一個EMF沒有問題。此外,如果我這樣做(與原始imgFmt):
imgFmt.Equals(ImageFormat.Emf)
然後它返回true,但仍然引發異常。
有沒有人知道爲什麼會發生這種情況並解決我的問題?
錯誤。我希望能夠導出到SVG ...看起來我需要一個EMF到SVG轉換器... – Goz