Example #1
0
        private void ExportTool()
        {
            IExport pExport = null;
            //  IExportJPEG pExportFormat;
            IWorldFileSettings pWorldFile = null;
            IExportImage       pExportType;
            IEnvelope          pEnv = new Envelope() as IEnvelope;
            int lResolution;

            lResolution = Convert.ToInt32(this.numericUpDown1.Value);
            switch (this.saveFileDialog1.Filter.ToString().Trim().Substring(0, 3))
            {
            case "jpg":
                pExport = new ExportJPEG() as IExport;
                break;

            case "bmp":
                pExport = new ExportBMP() as IExport;
                break;

            case "gif":
                pExport = new ExportGIF() as IExport;
                break;

            case "tif":
                pExport = new ExportTIFF() as IExport;
                break;

            case "png":
                pExport = new ExportPNG() as IExport;
                break;

            case "emf":
                pExport = new ExportEMF() as IExport;
                break;

            case "pdf":
                pExport = new ExportPDF() as IExport;
                break;

            case ".ai":
                pExport = new ExportAI() as IExport;
                break;

            case "svg":
                pExport = new ExportSVG() as IExport;
                break;

            case "ps":
                pExport = new ExportPS() as IExport;
                break;

            default:
                pExport = new ExportJPEG() as IExport;
                break;
            }

            if (this.textBox1.Text.ToString().Trim() != "")
            {
                if (System.IO.File.Exists(this.textBox1.Text.ToString()) == true)
                {
                    MessageBox.Show("该文件已经存在,请重新命名!");
                    this.textBox1.Text = "";
                    this.textBox1.Focus();
                }
                else
                {
                    pExport.ExportFileName = this.textBox1.Text;
                    pExport.Resolution     = lResolution;
                    pExportType            = pExport as IExportImage;
                    pExportType.ImageType  = esriExportImageType.esriExportImageTypeTrueColor;
                    pEnv                       = pActiveView.Extent;
                    pWorldFile                 = (IWorldFileSettings)pExport;
                    pWorldFile.MapExtent       = pEnv;
                    pWorldFile.OutputWorldFile = false;

                    tagRECT deviceRECT;
                    deviceRECT = Form1.m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();

                    IEnvelope pDriverBounds;
                    pDriverBounds = new Envelope() as IEnvelope;
                    pDriverBounds.PutCoords(deviceRECT.left, deviceRECT.bottom, deviceRECT.right, deviceRECT.top);
                    pExport.PixelBounds = pDriverBounds;

                    ITrackCancel pTrackCancel = new TrackCancel();
                    Form1.m_mapControl.ActiveView.Output(pExport.StartExporting(), lResolution, ref deviceRECT, pActiveView.Extent, pTrackCancel);

                    pExport.FinishExporting();
                    MessageBox.Show("打印图片保存成功!", "保存", MessageBoxButtons.OK);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("请保存文件!");
            }
        }
        //导出
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (tbxSavePath.Text.Trim() == "" || !tbxSavePath.Text.Trim().Contains("\\"))
            {
                MessageBox.Show("请选择正确的输出路径!", "提示");
                return;
            }
            IExport pExport = null;

            try
            {
                switch (pSimpleFiletype)
                {
                case "tif":
                    pExport = new ExportTIFF() as IExport;
                    break;

                case "EMF":
                    pExport = new ExportEMF() as IExport;
                    break;

                case "eps":
                    pExport = new ExportPS() as IExport;
                    break;

                case "ai":
                    pExport = new ExportAI() as IExport;
                    break;

                case "pdf":
                    pExport = new ExportPDF() as IExport;
                    break;

                case "svg":
                    pExport = new ExportSVG() as IExport;
                    break;

                case "bmp":
                    pExport = new ExportBMP() as IExport;
                    break;

                case "jpg":
                    pExport = new ExportEMF() as IExport;
                    break;

                case "png":
                    pExport = new ExportPNG() as IExport;
                    break;

                case "gif":
                    pExport = new ExportGIF() as IExport;
                    break;

                default:
                    return;
                }
                pExport.ExportFileName = pSavePath;
                pExport.Resolution     = pResolution;
                tagRECT pTagRECT;
                pTagRECT = pActiveView.ExportFrame;
                IPrintAndExport printAndExport = new PrintAndExport();
                printAndExport.Export(pActiveView, pExport, pResolution, false, null);
                Marshal.ReleaseComObject(pExport);
                MessageBox.Show("导出成功!", "提示");
            }
            catch (COMException ex)
            {
                MessageBox.Show("导出失败\n" + ex.Message, "错误");
                return;
            }
        }
Example #3
0
        public static void ExportActiveView2(IActiveView iactiveView_0, string string_0)
        {
            IExport export = null;
            tagRECT grect;

            switch (System.IO.Path.GetExtension(string_0).ToLower())
            {
            case ".emf":
                export = new ExportEMF() as IExport;
                break;

            case ".eps":
                export = new ExportPS() as IExport;
                break;

            case ".ai":
                export = new ExportAI() as IExport;
                break;

            case ".pdf":
                export = new ExportPDF() as IExport;
                break;

            case ".svg":
                export = new ExportSVG() as IExport;
                break;

            case ".bmp":
                export = new ExportBMP() as IExport;
                break;

            case ".jpg":
                export = new ExportJPEG() as IExport;
                break;

            case ".png":
                export = new ExportPNG() as IExport;
                break;

            case ".tif":
                export = new ExportTIFF() as IExport;
                break;

            case ".gif":
                export = new ExportGIF() as IExport;
                break;

            default:
                return;
            }
            export.ExportFileName = string_0;
            int num2 = 96;
            int num3 = 300;

            try
            {
                export.Resolution = num3;
                if (export is ISettingsInRegistry)
                {
                    (export as ISettingsInRegistry).RestoreDefault();
                }
            }
            catch
            {
            }
            grect.left   = 0;
            grect.top    = 0;
            grect.right  = iactiveView_0.ExportFrame.right * (num3 / num2);
            grect.bottom = iactiveView_0.ExportFrame.bottom * (num3 / num2);
            IEnvelope envelope = new Envelope() as IEnvelope;

            envelope.PutCoords((double)grect.left, (double)grect.top, (double)grect.right, (double)grect.bottom);
            export.PixelBounds = envelope;
            int hDC = export.StartExporting();

            iactiveView_0.Output(hDC, (int)export.Resolution, ref grect, null, null);
            export.FinishExporting();
            export.Cleanup();
        }