导出当前视图为BMP、JPG、PDF等格式
public void PageExport()
{
SaveFileDialog pSaveDlg = new SaveFileDialog();
pSaveDlg.Title = "导出图形";
pSaveDlg.DefaultExt = "pdf";
pSaveDlg.Filter = "PDF (*.pdf)|*.pdf|TIFF (*.tif)|*.tif|BMP (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|GIF (*.gif)|*.gif|EMF (*.emf)|*.emf|SVG (*.svg)|*.svg|AI (*.ai)|*.ai";
pSaveDlg.FilterIndex = 1;
pSaveDlg.RestoreDirectory = true;
pSaveDlg.OverwritePrompt = true;
if (pSaveDlg.ShowDialog() == DialogResult.OK)
{
string pFilePath = pSaveDlg.FileName;
IActiveView pActiveView = AxPageLayoutControl1.ActiveView;
IExport pExport;
tagRECT exportFrame;
IEnvelope pEnv;
int hdc;
int dpi;
exportFrame = pActiveView.ExportFrame;
pEnv = new EnvelopeClass();
pEnv.PutCoords(exportFrame.left, exportFrame.top, exportFrame.right, exportFrame.bottom);
switch (pSaveDlg.FilterIndex)
{
case 1://pdf
pExport = new ExportPDFClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 2://tif
pExport = new ExportTIFFClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 3://bmp
pExport = new ExportBMPClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 4://jpg
pExport = new ExportJPEGClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 5://gif
pExport = new ExportGIFClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 6://emf
pExport = new ExportEMFClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 7://svg
pExport = new ExportSVGClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
case 8://ai
pExport = new ExportAIClass();
dpi = (int)pExport.Resolution;
pExport.PixelBounds = pEnv;
pExport.ExportFileName = pSaveDlg.FileName;
pExport.Resolution = (short)dpi;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, dpi, ref exportFrame, null, null);
pExport.FinishExporting();
break;
default:
break;
}
MessageBox.Show("导出完毕!");
}
视图导出主要用到IExport 接口,在旧版本中采用IExporter接口,AE9以后替代为IExport,而且导出的类型也有增加。