private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir,string sOutputFileName, Boolean bClipToGraphicsExtent)
        {
            IActiveView docActiveView = m_hookHelper.ActiveView;
            IExport docExport;
            long iPrevOutputImageQuality;
            IOutputRasterSettings docOutputRasterSettings;
            IEnvelope PixelBoundsEnv;
            tagRECT exportRECT;
            tagRECT DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout docPageLayout;
            IEnvelope docMapExtEnv;
            long hdc;
            long tmpDC;
            long iScreenResolution;
            bool bReenable = false;

            IEnvelope docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;

            if (GetFontSmoothing())
            {
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    return;
                }
            }

            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {

                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("��֧�ֵ��������� " + ExportType + ", Ĭ�ϵ���ΪEMF��ʽ������");
                ExportType = "EMF";
                docExport = new ExportEMFClass();
            }

            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

            if (docExport is IExportImage)
            {
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                SetOutputQuality(docActiveView, lResampleRatio);
            }

            docExport.ExportFileName = sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];

            tmpDC = GetDC(0);
            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
            ReleaseDC(0, (int)tmpDC);
            frmSetResolution mSetResolution = new frmSetResolution(iOutputResolution);
            mSetResolution.ShowDialog();
            iOutputResolution = mSetResolution.m_Resolution ;
            docExport.Resolution = iOutputResolution;

            if (docActiveView is IPageLayout)
            {
                DisplayBounds = docActiveView.ExportFrame;
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
            }
            else
            {
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds = docDisplayTransformation.get_DeviceFrame();
            }

            PixelBoundsEnv = new Envelope() as IEnvelope;

            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
                docPageLayout = docActiveView as PageLayout;
                pUnitConvertor = new UnitConverter();

                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;

                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left = (int)(PixelBoundsEnv.XMin);
                exportRECT.top = (int)(PixelBoundsEnv.YMin);
                exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1;

                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio = iOutputResolution / iScreenResolution;
                double tempbottom = DisplayBounds.bottom * tempratio;
                double tempright = DisplayBounds.right * tempratio;
                exportRECT.bottom = (int)Math.Truncate(tempbottom);
                exportRECT.left = 0;
                exportRECT.top = 0;
                exportRECT.right = (int)Math.Truncate(tempright);

                PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

                docMapExtEnv = null;
            }
            docExport.PixelBounds = PixelBoundsEnv;

            try
            {
                hdc = docExport.StartExporting();
                docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);

                docExport.FinishExporting();
                docExport.Cleanup();

                MessageBox.Show("�ɹ����� " + sOutputDir + sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch
            {
                MessageBox.Show("�����ͼͼƬ�����г������⣡", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SetOutputQuality(docActiveView, iPrevOutputImageQuality);
                if (bReenable)
                {
                    EnableFontSmoothing();
                    bReenable = false;
                    if (!GetFontSmoothing())
                    {
                        MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                    }
                }

                docMapExtEnv = null;
                PixelBoundsEnv = null;
            }
        }
Exemple #2
0
        private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir, string sOutputFileName, Boolean bClipToGraphicsExtent)
        {
            IActiveView            docActiveView = m_hookHelper.ActiveView;
            IExport                docExport;
            long                   iPrevOutputImageQuality;
            IOutputRasterSettings  docOutputRasterSettings;
            IEnvelope              PixelBoundsEnv;
            tagRECT                exportRECT;
            tagRECT                DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout            docPageLayout;
            IEnvelope              docMapExtEnv;
            long                   hdc;
            long                   tmpDC;
            long                   iScreenResolution;
            bool                   bReenable = false;


            IEnvelope      docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;

            if (GetFontSmoothing())
            {
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    return;
                }
            }

            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {
                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("不支持的数据类型 " + ExportType + ", 默认导出为EMF格式的数据");
                ExportType = "EMF";
                docExport  = new ExportEMFClass();
            }


            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;


            if (docExport is IExportImage)
            {
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                SetOutputQuality(docActiveView, lResampleRatio);
            }

            docExport.ExportFileName = sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];


            tmpDC             = GetDC(0);
            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
            ReleaseDC(0, (int)tmpDC);
            frmSetResolution mSetResolution = new frmSetResolution(iOutputResolution);

            mSetResolution.ShowDialog();
            iOutputResolution    = mSetResolution.m_Resolution;
            docExport.Resolution = iOutputResolution;


            if (docActiveView is IPageLayout)
            {
                DisplayBounds        = docActiveView.ExportFrame;
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
            }
            else
            {
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds            = docDisplayTransformation.get_DeviceFrame();
            }

            PixelBoundsEnv = new Envelope() as IEnvelope;

            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
                docPageLayout        = docActiveView as PageLayout;
                pUnitConvertor       = new UnitConverter();

                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;

                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left   = (int)(PixelBoundsEnv.XMin);
                exportRECT.top    = (int)(PixelBoundsEnv.YMin);
                exportRECT.right  = (int)(PixelBoundsEnv.XMax) + 1;

                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio  = iOutputResolution / iScreenResolution;
                double tempbottom = DisplayBounds.bottom * tempratio;
                double tempright  = DisplayBounds.right * tempratio;
                exportRECT.bottom = (int)Math.Truncate(tempbottom);
                exportRECT.left   = 0;
                exportRECT.top    = 0;
                exportRECT.right  = (int)Math.Truncate(tempright);

                PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

                docMapExtEnv = null;
            }
            docExport.PixelBounds = PixelBoundsEnv;

            try
            {
                hdc = docExport.StartExporting();
                docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);

                docExport.FinishExporting();
                docExport.Cleanup();

                MessageBox.Show("成功导出 " + sOutputDir + sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "输出地图图片", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("输出地图图片过程中出现问题!", "输出地图图片", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SetOutputQuality(docActiveView, iPrevOutputImageQuality);
                if (bReenable)
                {
                    EnableFontSmoothing();
                    bReenable = false;
                    if (!GetFontSmoothing())
                    {
                        MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                    }
                }


                docMapExtEnv   = null;
                PixelBoundsEnv = null;
            }
        }