zoukankan      html  css  js  c++  java
  • arcgis engine指定范围导出屏幕图片

    地理坐标下,所以要转换为度。

    arcgis engine 10.2.2 +vs2010

            [DllImport("GDI32.dll")]
            public static extern int GetDeviceCaps(int hdc, int nIndex);
    
            /* User32 delegates to getDC and ReleaseDC */
            [DllImport("User32.dll")]
            public static extern int GetDC(int hWnd);
    
            [DllImport("User32.dll")]
            public static extern int ReleaseDC(int hWnd, int hDC);
    
            [DllImport("user32.dll", SetLastError = true)]
            static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);
    
            /// <summary>
            /// 地图距离转屏幕像素数,不同缩放比例尺下同样距离对应像素数不同的,有特殊需要时设置sMapBLC
            /// </summary>
            /// <param name="pAV">The p AV.</param>
            /// <param name="dMapUnits">地图距离</param>
            /// <returns></returns>
            public static double ConvertMapUnitsToPixels(IActiveView pAV, double dMapUnits)
            {
                IDisplayTransformation pDT = pAV.ScreenDisplay.DisplayTransformation;
                tagRECT pDeviceFrame = pDT.get_DeviceFrame();
                int iDeviceLeft = pDeviceFrame.left;
                int iDeviceRight = pDeviceFrame.right;
                int iPixelExtent = iDeviceRight - iDeviceLeft;
                double dRealWorldExtent = pAV.Extent.Width;
                double dSizeOfEachPixel = dRealWorldExtent / iPixelExtent;
                return dMapUnits / dSizeOfEachPixel;
            }
    
            /// <summary>
            /// 指定范围裁剪图片
            /// </summary>
            /// <param name="pMap">裁图地图窗口</param>
            /// <param name="pExtent">指定裁图范围</param>
            /// <param name="strPicFile">输出文件名称</param>
            /// <param name="iOutResolution">输出DPI</param>
            public static void ClipMap2Pic(IActiveView pAV, IEnvelope pExtent, string strPicFile, int iOutResolution)
            {
                if (pAV == null) return;
                if (strPicFile == string.Empty) return;
    
                string ext = strPicFile.Substring(strPicFile.Length - 4).ToUpper();
                IExport pExport = null;
                if (ext == ".TIF")            //根据文件名后4位判断输出类型
                    pExport = new ExportTIFFClass();
                else if (ext == ".EMF")
                    pExport = new ExportEMFClass();
                else if (ext == ".BMP")
                    pExport = new ExportBMPClass();
                else if (ext == ".GIF")
                    pExport = new ExportGIFClass();
                else if (ext == ".PDF")
                    pExport = new ExportPDFClass();
                else
                    if (ext == ".PNG")
                        pExport = new ExportPNGClass();
                    else if (ext == ".SVG")
                            pExport = new ExportSVGClass();
                    else if (strPicFile.Substring(strPicFile.Length - 4).ToUpper() == ".AI")
                            pExport = new ExportAIClass();
                    else if (ext == ".EPS")
                            pExport = new ExportPSClass();
                    else
                        pExport = new ExportJPEGClass();
    
                IDisplayTransformation pDT = pAV.ScreenDisplay.DisplayTransformation;
    
                IOutputRasterSettings docOutputRasterSettings = pDT as IOutputRasterSettings;
                int iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;
                docOutputRasterSettings.ResampleRatio = 1;
    
                /* Get the device context of the screen */
                long tmpDC = GetDC(0);
                /* Get the screen resolution. */
                int iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
                /* release the DC. */
                ReleaseDC(0, (int)tmpDC);
    
                // 根据传入的pExtent确定裁图的画布大小(出图比例尺下裁图范围的像素高和宽)
                tagRECT ptagTmp;
                ptagTmp.left = 0; 
                ptagTmp.top = 0;
                ptagTmp.right = (int)Math.Truncate(ConvertMapUnitsToPixels(pAV, pExtent.Width) * iOutResolution / iScreenResolution); //把地图距离转为屏幕像素个数
                ptagTmp.bottom = (int)Math.Truncate(ConvertMapUnitsToPixels(pAV, pExtent.Height) * iOutResolution / iScreenResolution);
                IEnvelope pEnvNew = new EnvelopeClass();
                pEnvNew.PutCoords(ptagTmp.left, ptagTmp.top, ptagTmp.right, ptagTmp.bottom); //裁图的画布大小
    
                pExport.ExportFileName = strPicFile;
                pExport.Resolution = iOutResolution;
                pExport.PixelBounds = pEnvNew;
                if (ext == ".TIF")
                {
                    (pExport as IExportTIFF).GeoTiff = true;//包含tif文件坐标信息,这2句是必须的
                    (pExport as IWorldFileSettings).MapExtent = pExtent;
                    (pExport as IExportTIFF).CompressionType = esriTIFFCompression.esriTIFFCompressionJPEG;
                }
    
                if (ext == ".PDF")
                {
                    (pExport as IExportPDF).Compressed = true;
                    (pExport as IExportPDF).EmbedFonts = true;
                    (pExport as IExportPDF).ImageCompression = esriExportImageCompression.esriExportImageCompressionNone;
                }
    
                int ihdc = pExport.StartExporting();
                pAV.Output(ihdc, iOutResolution, ref ptagTmp, pExtent, null);
                pExport.FinishExporting();
    
                pExport.Cleanup();
                (pDT as IOutputRasterSettings).ResampleRatio = iPrevOutputImageQuality;
            }
    
            void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
            {
                if (isExportMode)
                {
                    IEnvelope bounds = new EnvelopeClass();
                    double dis = 100;//100米
                    IUnitConverter convert = new UnitConverterClass();
                    double degree = convert.ConvertUnits(dis, esriUnits.esriMeters, esriUnits.esriDecimalDegrees);//转换为度
                    bounds.PutCoords(e.mapX - degree, e.mapY + degree, e.mapX + degree, e.mapY - degree);
    
                    string file = System.IO.Path.Combine(@"D:	est22image", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg");
                    ClipMap2Pic(this.axMapControl1.ActiveView, bounds, file, 96);
                }
            }
  • 相关阅读:
    快速生成树协议 RSTP
    VLAN间路由
    二层交换机原理
    网络安全系统之四 PKI体系
    网络安全系统之三 数字证书
    生成树协议 STP
    网络安全系统之二 数字签名
    网络安全系统之一 加密算法
    系统可靠性
    DNS资源记录
  • 原文地址:https://www.cnblogs.com/yansc/p/14006344.html
Copyright © 2011-2022 走看看