是否有人知道用于在WinForms和Microsoft Service Reports / CrystalReports中显示CGM文件的.NET C#库,以便它也可以打印?
如果它还能够将文件转换为jpeg,gif,png等网络友好的图形格式,那将非常有用。
这可能是来自.NET Library for CGM File Conversion的重复问题,但OP没有标记答案,也没有建议的解决方案.NET兼容。
所以我只是再试一次运气。谢谢你的帮助。
答案 0 :(得分:3)
我只想与SO分享这个临时黑客。如果可能的话,我仍然需要一个合适的库(在所有在线提供.NET excel教程的人都可以获得积分):
using System;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Core;
using System.Drawing;
namespace CGM
{
public class CGMConverter
{
Image _mImage;
public Image Image { get { return _mImage; } }
public CGMConverter(string cgm, float width, float height)
{
object misValue = System.Reflection.Missing.Value;
Excel.Application xlsApp = null;
Excel.Workbook xlsWorkBook = null;
Excel.Worksheet xlsWorkSheet = null;
try
{
xlsApp = new Excel.ApplicationClass();
xlsWorkBook = xlsApp.Workbooks.Add(misValue);
xlsWorkSheet = (Excel.Worksheet)xlsWorkBook.Sheets["sheet1"];
xlsWorkSheet.Shapes.AddPicture(cgm, MsoTriState.msoFalse, MsoTriState.msoTrue, 50, 50, width, height);
xlsWorkSheet.Shapes.Item(0).Copy();
_mImage = System.Windows.Forms.Clipboard.GetImage();
}
catch(Exception e)
{
throw (e);
}
finally
{
xlsApp.DisplayAlerts = false;
xlsApp.Quit();
releaseObject(xlsWorkSheet);
releaseObject(xlsWorkBook);
releaseObject(xlsApp);
}
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
}
finally
{
GC.Collect();
}
}
}
}