Loading

SilverLight For Arcgis 导出图片保存到本地注意点。。。

参考出处:http://bbs.esrichina-bj.cn/ESRI/thread-59271-1-1.html 

使用上面提供的方法需要注意的地方:

1:url路径可能不对需要自己根据情况调整下。

2:有的图层可能需要传入token

GetUrl方法需要修改 

  private static string GetUrl(PrintArea area, string url,string token)

    {

        StringBuilder uri = new StringBuilder();

        uri.AppendFormat("{0}/export?", url);

        uri.AppendFormat(System.Globalization.CultureInfo.InvariantCulture,

            "bbox={0},{1},{2},{3}", area.XMin, area.YMin, area.XMax, area.YMax);

        uri.AppendFormat("&size={0},{1}", area.Width, area.Height);

        uri.Append("&format=png32");

        uri.Append("&transparent=true");

        if (area.SpatialReferenceID.HasValue)

        {

            uri.AppendFormat("&imageSR={0}&bboxSR={0}", area.SpatialReferenceID);

        }

        uri.Append("&f=image");

        uri.Append("&token=" + token);

        return uri.ToString();

    } 

3 .奖生成的图片转成stream的时候要用ImageFormat.Png,如果是mageFormat.jpeg那么所有透明的地方都会被黑色替代

            MemoryStream stream = new MemoryStream();

            image.Save(stream, ImageFormat.Png);

            byte[] data = new byte[(int)stream.Length]; 

 

4:下载图片

        protected void Button1_Click(object sender, EventArgs e)

        {

            WebClient client = new WebClient();

            string id = Request.QueryString[0];

            string url = "http://" + Request.Url.Authority + "/GetImagePrint.ashx?id="+id;

            WebClient wc = new WebClient();

            var bytes = wc.DownloadData(url);


            Response.Buffer = true;

            Page.Response.Clear();//清除缓冲区所有内容

            Page.Response.ContentType = "application/octet-stream";

            Page.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("print.jpg"));

            byte[] file = bytes;

            int a = file.Length;

            Response.BinaryWrite(file);

            Response.Flush();

            Response.End();

        } 

posted @ 2010-09-26 14:22  Agile.Zhou  阅读(609)  评论(0编辑  收藏  举报