微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ArcGIS Silverlight API 输出地图保存到图片

通过ArcGISsilverlight API实现输出地图到图片常用的有如下两种方式:向服务器端发送http请求、通过WriteableBitmap类在客户端直接对地图控件截图。

    向服务器端发送http请求方式 虽然可以做到输出指定矩形范围的地图、设置控件参考、支持Png/jpg/bmp等图片格式,但这种方式每次只能对单一的地图服务进行截图,换句话讲,当我们叠加了多个地图服务时没有办法将输出区域内所有的地图服务一起输出;这种方式也不支持对Graphiclayer图层输出

选择地图输出区域

服务器端返回的图片

privatevoid Exportimage(ESRI.ArcGIS.Client.Geometry.Geometry extent)

 

       {

 

           try

 

           {

 

                EnvelopesEnv = extent.Extent;

 

                StringBuilder sUrl = newStringBuilder();

 

                sUrl.Append(“http://lingy/ArcGIS/rest/services/dxmap/MapServer);

 

                sUrl.Append(“/Export?);

 

                sUrl.Append(“f=json);

 

                sUrl.Append(String.Format(“&bBox={0},{1},{2},{3},sEnv.XMin,sEnv.YMin,sEnv.XMax,sEnv.YMax));

 

                sUrl.Append(“&format=);

 

                sUrl.Append(“png);

 

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sbUrl.ToString());

 

                request.BeginGetResponse(newAsyncCallback(ExportCall),request);

 

           }

 

           catch (Exception ex)

 

           {

 

                MessageBox.Show(导出图片失败: + ex.ToString());

 

           }

 

       }

 

       privatevoid ExportCall(IAsyncResult asynchronousResult)

 

       {

 

           this.dispatcher.BeginInvoke(delegate()

 

           {

 

                try

 

                {

 

                    HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

 

                    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

 

                    Streamstream = response.GetResponseStream();

 

                    StreamReader reader = newStreamReader(stream);

 

                    stringresult = reader.ReadToEnd();

 

                    stringhref = result.Split(newchar[] { “”" })[3];

 

                    linkImageResult.NavigateUri= newUri(href,UriKind.Absolute);

 

                }

 

                catch (Exception ex)

 

                {

 

                    MessageBox.Show(导出图片失败: + ex.ToString());

 

                }

 

           });

 

       }

WriteableBitmap可以在客户端直接对地图控件截图保存,保存的图片格式需要自己编写格式编码。

通过WriteableBitmap截图源码:

privatevoid button1_Click(object sender,RoutedEventArgs e)

        {

            try

            {

 

                cMapExportToImageimageExporter = newcMapExportToImage();

 

                bool bResult =imageExporter.ExportPNG(mainMap asUIElement);

 

                string strResult =bResult ? “成功!“ : “失败!“;

 

                MessageBox.Show(图片导出“ +strResult);

 

            }

 

            catch (Exception pEr)

 

            {

 

                string msg =pEr.Message;

 

            }

 

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐