using Container.Common; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace Container.Win { /// /// NavGuide.xaml 的交互逻辑 /// public partial class NavGuide : UserControl { Class_Log log = new Class_Log(); public NavGuide(double width, int height, string logo, string name = "", string distance = "", double angle = 0) { InitializeComponent(); try { //this.Width = width; //log.WriteLogFile(width.ToString(), "NavGuide"); //log.WriteLogFile(height.ToString(), "NavGuide"); //log.WriteLogFile((width - 40).ToString(), "NavGuide"); //WinRect.Rect = new Rect(0, 0,width - 80, 200); ImgRotate.Angle = angle; Uri uri = new Uri(logo, UriKind.Absolute); this.ImgLogo.Source = BitmapFrame.Create(uri); TxtName.Text = name; TxtDistance.Text = distance; } catch (Exception e) { log.WriteLogFile(e.ToString(), "NavGuide"); } } public static byte[] GetImageFromResponse(string url, string cookie = null) { redo: try { System.Net.WebRequest request = System.Net.WebRequest.Create(url); if (!string.IsNullOrWhiteSpace(cookie)) { request.Headers[System.Net.HttpRequestHeader.Cookie] = cookie; } System.Net.WebResponse response = request.GetResponse(); using (Stream stream = response.GetResponseStream()) { using (MemoryStream ms = new MemoryStream()) { Byte[] buffer = new Byte[1024]; int current = 0; do { ms.Write(buffer, 0, current); } while ((current = stream.Read(buffer, 0, buffer.Length)) != 0); return ms.ToArray(); } } } catch (System.Net.WebException ex) { if (ex.Message == "基础连接已经关闭: 发送时发生错误。") { goto redo; } else { throw; } } } } }