ImgeDefine.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Media.Imaging;
  10. using WeChatCore.DefineClass;
  11. namespace WeChatCore.Control
  12. {
  13. public class ImgeDefine : Image
  14. {
  15. private static readonly DependencyProperty ImageSourceDefineProperty = DependencyProperty.Register("ImageSourceDefine", typeof(string), typeof(ImgeDefine), new PropertyMetadata(new PropertyChangedCallback(ImageSourceCallBack)));
  16. private static void ImageSourceCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
  17. {
  18. ImgeDefine id = d as ImgeDefine;
  19. //ToDo
  20. new Task(() =>
  21. {
  22. List<byte> b = (List<byte>)HttpHelper.HttpMethods.GetFile(UrlDefine.RootUrl + id.ImageSourceDefine, "", CommonDefine.Cookies).ContentData;
  23. Application.Current.Dispatcher.Invoke(new Action(() =>
  24. {
  25. MemoryStream ms = new MemoryStream(b.ToArray());
  26. BitmapImage bi = new BitmapImage();
  27. bi.BeginInit();
  28. bi.StreamSource = ms;// new FileStream();
  29. bi.EndInit();
  30. id.Source = bi;
  31. }));
  32. }).Start();
  33. //if (string.IsNullOrWhiteSpace(HeadUrlDef))
  34. //{
  35. // // string uuid = MethodsHelper.MsgSaveFile(DirectoryDefine.HeaderImagePath);
  36. // HttpHelper.HttpMethods.GetFile(UrlDefine.RootUrl + HeadImgUrl, Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + uuid + ".jpg", CommonDefine.Cookies);
  37. // Application.Current.Dispatcher.Invoke(new Action(() =>
  38. // {
  39. // id.Source = Environment.CurrentDirectory + "\\" + DirectoryDefine.HeaderImagePath + "\\" + uuid + ".jpg";
  40. // }));
  41. //}
  42. //else
  43. //{
  44. // LogWriter.Write(string.Format("当前人员{0}已有头像", DisplayNameDef), LogPathDefine.WeChatLogPath);
  45. //}
  46. }
  47. public string ImageSourceDefine
  48. {
  49. get
  50. {
  51. return (string)GetValue(ImageSourceDefineProperty);
  52. }
  53. set
  54. {
  55. SetValue(ImageSourceDefineProperty, value);
  56. }
  57. }
  58. }
  59. }