コード例 #1
0
ファイル: 720Yun.cs プロジェクト: ssjylsg/pano
        public void GenerateFile(SceneItem item, string scenePath, int max, int maxZoom)
        {
            GC.Collect();
            CubeImage cubeImage  = item.CubeImages[maxZoom - 1];
            int       otherWidth = int.Parse(cubeImage.TiledImageWidth) % item.Tilesize;

            for (int d = 0; d < directory.Length; d++)
            {
                if (File.Exists(Path.Combine(scenePath, directory[d] + ".jpg")))
                {
                    continue;
                }
                using (var image = new Bitmap(int.Parse(cubeImage.TiledImageWidth), int.Parse(cubeImage.TiledImageHeight)))
                {
                    using (Graphics g = Graphics.FromImage(image))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;

                        for (int i = 1; i < max; i++)
                        {
                            for (int j = 1; j < max; j++)
                            {
                                using (
                                    var img =
                                        Image.FromFile(Path.Combine(scenePath, cubeImage.Level.ToString(),
                                                                    string.Format("{2}{0}_{1}.jpg", i, j, directory[d]))))
                                {
                                    g.DrawImage(img, item.Tilesize * (j - 1), item.Tilesize * (i - 1),
                                                j != max - 1 ? item.Tilesize : otherWidth,
                                                i != max - 1 ? item.Tilesize : otherWidth);
                                }
                            }
                        }
                    }
                    try
                    {
                        if (directory[d] == 'u')
                        {
                            image.Save(Path.Combine(scenePath, directory[d] + "1.jpg"), ImageFormat.Jpeg);
                            image.RotateFlip(RotateFlipType.Rotate90FlipXY);
                        }
                        if (directory[d] == 'd')
                        {
                            image.Save(Path.Combine(scenePath, directory[d] + "1.jpg"), ImageFormat.Jpeg);
                            image.RotateFlip(RotateFlipType.Rotate270FlipXY);
                        }
                    }
                    catch (Exception e)
                    {
                        OnOnError(e);
                    }
                    image.Save(Path.Combine(scenePath, directory[d] + ".jpg"), ImageFormat.Jpeg);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="pano_id"></param>
        /// <param name="configUrl">默认为 http://xml.qncdn.720static.com/@/{0}/{0}.xml </param>
        /// <returns></returns>
        public Pano72Yun GetPicUrlByKey(string key, string pano_id, string configUrl = "http://xml.qncdn.720static.com/@/{0}/{0}.xml")
        {
            var         list        = new List <SceneItem>();
            var         content     = HttpHelper.GetRequestContent(string.Format(configUrl, key));
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(content);
            var scenes = xmlDocument.SelectNodes("krpano/scene");

            // 解析场景
            for (int i = 0; i < scenes.Count; i++)
            {
                var item = new SceneItem()
                {
                    PanoId     = scenes[i].Attributes["pano_id"].InnerText,
                    PreViewUrl = scenes[i].SelectSingleNode("preview").Attributes["url"].InnerText
                };
                item.Tilesize = int.Parse(scenes[i].SelectSingleNode("image").Attributes["tilesize"].InnerText);
                var nodes = scenes[i].SelectSingleNode("image").SelectNodes("level");
                for (int j = 0; j < nodes.Count; j++)
                {
                    var url = nodes[j].SelectSingleNode("cube").Attributes["url"].InnerText;
                    item.CubeImages.Add(new CubeImage()
                    {
                        Url = url,
                        TiledImageHeight = nodes[j].Attributes["tiledimageheight"].InnerText,
                        TiledImageWidth  = nodes[j].Attributes["tiledimagewidth"].InnerText,
                        Level            = int.Parse(url.Substring(url.IndexOf("/imgs/%s/") + "/imgs/%s/".Length, 2).Trim('l'))
                    });
                }
                list.Add(item);
            }
            // 解析场景thumb
            var config = xmlDocument.SelectNodes("krpano/config/thumbs/category/pano");
            var dic    = new Dictionary <string, dynamic>();

            for (int i = 0; i < config.Count; i++)
            {
                dic[config[i].Attributes["pano_id"].InnerText] = new
                {
                    thumb = config[i].Attributes["thumb"].InnerText,
                    title = config[i].Attributes["title"].InnerText,
                };
            }
            list.ForEach(scene =>
            {
                scene.Thumb = dic[scene.PanoId].thumb;
                scene.Title = dic[scene.PanoId].title;
            });
            return(new Pano72Yun()
            {
                Config = content, SceneItems = list, Key = pano_id, Id = key
            });
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="pano_id"></param>
        /// <param name="configUrl">默认为 http://www.new720.com/tour/xml?id={0} </param>
        /// <returns></returns>
        public Pano72Yun GetPanoNew72YunByKey(string key, string pano_id, string configUrl = "http://www.new720.com/tour/xml?id={0}")
        {
            var         list        = new List <SceneItem>();
            var         content     = HttpHelper.GetRequestContent(string.Format(configUrl, key));
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(content);
            var scenes = xmlDocument.SelectNodes("krpano/scene");

            // 解析场景
            for (int i = 0; i < scenes.Count; i++)
            {
                var item = new SceneItem()
                {
                    PanoId     = scenes[i].Attributes["name"].InnerText,
                    Thumb      = scenes[i].Attributes["thumburl"].InnerText,
                    Title      = scenes[i].Attributes["title"].InnerText,
                    PreViewUrl = scenes[i].SelectSingleNode("preview").Attributes["url"].InnerText
                };
                item.Tilesize = int.Parse(scenes[i].SelectSingleNode("image").Attributes["tilesize"].InnerText);
                var nodes = scenes[i].SelectSingleNode("image").SelectNodes("level");

                for (int j = 0; j < nodes.Count; j++)
                {
                    var url = nodes[j].SelectSingleNode("cube").Attributes["url"].InnerText;
                    item.CubeImages.Add(new CubeImage()
                    {
                        Url = url,
                        TiledImageHeight = nodes[j].Attributes["tiledimageheight"].InnerText,
                        TiledImageWidth  = nodes[j].Attributes["tiledimagewidth"].InnerText,
                        Level            = int.Parse(url.Substring(url.IndexOf("/panos/%s/") + "/panos/%s/".Length, 2).Trim('l'))
                    });
                }
                list.Add(item);
            }

            return(new Pano72Yun()
            {
                Config = content, SceneItems = list, Key = pano_id, Id = key
            });
        }