public void Init(string imgUrl, string goodsUrl, ChatDesk desk) { this._imgUrl = imgUrl; this._desk = desk; this._goodsUrl = goodsUrl; WebImageHelper.GetImageFromUrl(imgUrl, this.imgGoods, false); }
private static void DownImageAndSave(string url) { if (!string.IsNullOrEmpty(url)) { string text = WebImageHelper.GetImageFileName(url); FileEx.DeleteWithoutException(text); using (WebClient webClient = new WebClient()) { try { webClient.DownloadFile(url, text); } catch (Exception e) { Log.Exception(e); Log.Info("无法下载图片,url=" + url); } } try { BitmapImageEx.ResizeImageAndSave(text, 300); } catch (Exception e2) { Log.Exception(e2); } } }
public static async void GetImageFromUrl(string url, Image image, bool useCache = false) { BitmapImage img = useCache ? null : WebImageHelper.ReadImageFromCachedFile(url); if (img == null) { image.Source = WebImageHelper.ImgLoading; await Task.Factory.StartNew(() => { DownImageAndSave(url); }, TaskCreationOptions.LongRunning); img = WebImageHelper.ReadImageFromCachedFile(url); } image.Source = img; }
private void imgGoods_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 1) { if (e.ChangedButton == MouseButton.Left) { this._desk.Editor.SetPlainText(this._goodsUrl, true, true); } else { WebImageHelper.GetImageFromUrl(this._imgUrl, this.imgGoods, true); } } else if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left) { this._desk.Editor.SendPlainText(this._goodsUrl); } }
private static BitmapImage ReadImageFromCachedFile(string url) { BitmapImage img = null; lock (_synobj) { try { string filename = WebImageHelper.GetImageFileName(url); img = BitmapImageEx.CreateFromFile(filename, 3); } catch (Exception e) { Log.Exception(e); } } return(img); }
private void OnMouseEnter() { try { this._isMouseInsideImageControl = true; this._mouseEnterTime = DateTime.Now; if (this.imgGoods.Source != null && this.imgGoods.Source != WebImageHelper.ImgLoading && this.Wnd != null) { DelayCaller.CallAfterDelayInUIThread(() => { if (this._isMouseInsideImageControl && this.Wnd.imgBig.Source == null) { this.Wnd.BringTop(); this.Wnd.imgBig.Width = 300.0; this.Wnd.imgBig.Height = 300.0; Point point = base.TranslatePoint(new Point(base.ActualWidth + 5.0, 0.0), this.Wnd); if (point.Y + this.Wnd.imgBig.Height > SystemParameters.WorkArea.Height) { point.Y = SystemParameters.WorkArea.Height - this.Wnd.imgBig.Height - 5.0; } this.Wnd.imgBig.SetValue(Canvas.LeftProperty, point.X); this.Wnd.imgBig.SetValue(Canvas.TopProperty, point.Y); WebImageHelper.GetImageFromUrl(this._imgUrl, this.Wnd.imgBig, false); DelayCaller.CallAfterDelayInUIThread(() => { if (this._isMouseInsideImageControl && this._mouseEnterTime.xElapse().TotalSeconds > 9.0) { this.OnMouseLeave(); } }, 10000); } }, 200); } } catch (Exception e) { Log.Exception(e); } }