ArcEngine 地图图片输出 栅格不清晰

来源:互联网 发布:mac如何下载视频 编辑:程序博客网 时间:2024/05/01 22:40

很久之前发现的问题,地图图片使用IExport方法输出的栅格图片不够清晰(96dpi和300dpi看起来完全一样) 

找了很久也没找到合适的方法,之前用的笨办法是将IExport.PixelBounds放大来实现输出的栅格图片的清晰度,这两天好好看了一下,发现使用IPrintAndExport接口的Export方法输出的栅格很清晰  但是不能输出指定矩形框范围的图片

最后发现设置IActiveView.ScreenDisplay.DisplayTransformation 转换为 IOutputRasterSettings,改变它的ResampleRatio为1即可输出清晰的栅格


贴上两种输出清晰图片的代码


        /// <summary>
        /// 生成当前地图图片
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="outputResolution">分辨率</param>
        /// <param name="pathFileName">文件名</param>
        /// <returns></returns>
        public static bool CreateJPEGHIResolutionFromActiveView(IActiveView activeView, int outputResolution, string pathFileName)
        {
            IExport export = new ExportJPEGClass();
            export.ExportFileName = pathFileName;
            IPrintAndExport docPrintExport = new PrintAndExportClass();
            docPrintExport.Export(activeView, export, outputResolution, true, null);
            return true;
        }


        /// <summary>
        /// 生成指定Envelope范围的图片
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="fileName">名称</param>
        /// <param name="env">范围</param>
        /// <param name="dpi">分辨率</param>
        /// <returns></returns>
        public static bool ExportMapToImage(IActiveView activeView, string fileName,  IEnvelope env,  int dpi)
        {
            try
            {
                IExport export = null;
                string filter = fileName.Substring(fileName.LastIndexOf('.'));
                switch (filter)
                {
                    case ".jpg":
                        export = new ExportJPEGClass();
                        break;
                    case ".bmp":
                        export = new ExportBMPClass();
                        break;
                    case ".emf":
                        export = new ExportEMFClass();
                        break;
                    case ".gif":
                        export = new ExportGIFClass();
                        break;
                    case ".ai":
                        export = new ExportAIClass();
                        break;
                    case ".pdf":
                        export = new ExportPDFClass();
                        break;
                    case ".png":
                        export = new ExportPNGClass();
                        break;
                    case ".eps":
                        export = new ExportPSClass();
                        break;
                    case ".svg":
                        export = new ExportSVGClass();
                        break;
                    case ".tif":
                        export = new ExportTIFFClass();
                        break;
                    default:
                        //MessageBox.Show("输出格式错误");
                        return false;
                }
                double screenResolution = activeView.ScreenDisplay.DisplayTransformation.Resolution;
                tagRECT exportRECT;
                exportRECT.left = 0;
                exportRECT.top = 0;
                int pixw = 0;
                int pixh = 0;
                pixw = (int)(env.Width * (dpi / screenResolution));
                pixh = (int)(env.Height * (dpi / screenResolution));
                exportRECT.right = pixw;
                exportRECT.bottom = pixh;
                IEnvelope pEnv = new EnvelopeClass();
                pEnv.PutCoords(exportRECT.left, exportRECT.bottom, exportRECT.right, exportRECT.top);
                export.PixelBounds = pEnv;
                export.ExportFileName = fileName;
                export.Resolution = dpi;
                IOutputRasterSettings pOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
                pOutputRasterSettings.ResampleRatio = 1;
                activeView.Output(export.StartExporting(), dpi, ref exportRECT, env, null);
                export.FinishExporting();
                export.Cleanup();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(export);
                return true;
            }
            catch 
            {
                return false;
            }
        }


原创粉丝点击