完成小头像管理器,优化我的信息头像加载器,v1.6.13

This commit is contained in:
dathlin
2017-10-14 21:21:33 +08:00
parent d43866b443
commit 2a3a0c5f98
12 changed files with 415 additions and 427 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace Wpf
{
/***********************************************************************************
*
* 说明用于开发一些wpf专有的方法一些转换方法
*
***********************************************************************************/
public class AppWpfHelper
{
public static BitmapImage TranslateImageToBitmapImage(System.Drawing.Bitmap bitmap)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
if(bitmap.RawFormat != null) bitmap.Save(ms, bitmap.RawFormat);
else bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
return bi;
}
}
}

View File

@@ -70,6 +70,8 @@ namespace 软件系统客户端Wpf
public MainWindow()
{
InitializeComponent();
UserClient.PortraitManager = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory);
}
#endregion
@@ -112,10 +114,10 @@ namespace 软件系统客户端Wpf
//窗口显示
IsWindowShow = true;
//udp测试
//SendServerUdpData(0, "显示了窗体");
// udp测试
// SendServerUdpData(0, "显示了窗体");
//是否显示更新日志,显示前进行判断该版本是否已经显示过了
// 是否显示更新日志,显示前进行判断该版本是否已经显示过了
if (!UserClient.JsonSettings.IsNewVersionRunning)
{
UserClient.JsonSettings.IsNewVersionRunning = false;
@@ -126,7 +128,7 @@ namespace 软件系统客户端Wpf
//根据权限使能菜单
// 根据权限使能菜单
if(UserClient.UserAccount.Grade < AccountGrade.Admin)
{
MenuItem公告管理.IsEnabled = false;
@@ -145,15 +147,15 @@ namespace 软件系统客户端Wpf
}
//启动网络服务
// 启动网络服务
Net_Socket_Client_Initialization();
//启动定时器
// 启动定时器
TimeTickInitilization();
//显示头像
SoftUserPortraitInitialization();
SoftUserPortrait.LoadUserSmallPortraint();
// 显示名称和加载头像
AccountChip.Content = UserClient.UserAccount.UserName;
AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
UserClient.PortraitManager.GetSmallPortraitByUserName(UserClient.UserAccount.UserName));
SetShowRenderControl(UIControl_Home);
}
@@ -328,7 +330,7 @@ namespace 软件系统客户端Wpf
private void MenuItem我的信息_Click(object sender, RoutedEventArgs e)
{
using (FormAccountDetails form = new FormAccountDetails(SoftUserPortrait))
using (FormAccountDetails form = new FormAccountDetails())
{
form.ShowDialog();
}
@@ -403,8 +405,17 @@ namespace 软件系统客户端Wpf
}
}
private void AccountChip_Click(object sender, RoutedEventArgs e)
{
// 点击了头像,请求查看高清版本头像
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", UserClient.PortraitManager.ThreadPoolDownloadSizeLarge))
{
fmr.ShowDialog();
}
}
#endregion
#region
private NetComplexClient net_socket_client = new NetComplexClient();
@@ -544,8 +555,14 @@ namespace 软件系统客户端Wpf
}
else if(customer == CommonHeadCode.MultiNetHeadCode.)
{
UserClient.PortraitManager.UpdateSmallPortraitByName(data);
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
{
if (data == UserClient.UserAccount.UserName)
{
AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
UserClient.PortraitManager.GetSmallPortraitByUserName(data));
}
foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children)
{
m.UpdatePortrait(data);
@@ -694,50 +711,7 @@ namespace 软件系统客户端Wpf
}
#endregion
#region
private UserPortrait SoftUserPortrait { get; set; }
private void SoftUserPortraitInitialization()
{
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory +
@"Portrait\" + UserClient.UserAccount.UserName, ShowSmallPortrait);
}
private void ShowSmallPortrait(System.Drawing.Bitmap bitmap)
{
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
{
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, bitmap.RawFormat);
bitmap.Dispose();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
AccountPortrait.Source = bi;
}));
}
private void AccountChip_Click(object sender, RoutedEventArgs e)
{
// 点击了头像,请求查看高清版本头像
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", SoftUserPortrait.ThreadPoolDownloadSizeLarge))
{
fmr.ShowDialog();
}
}
#endregion
#region
private List<UserControl> all_main_render = new List<UserControl>();

View File

@@ -100,26 +100,11 @@ namespace 软件系统客户端Wpf.Views.Controls
// 向服务器请求小头像
if (obj is NetAccount m_NetAccount)
{
try
System.Drawing.Bitmap bitmap = UserClient.PortraitManager.GetSmallPortraitByUserName(m_NetAccount.UserName);
Dispatcher.Invoke(new Action(() =>
{
System.Drawing.Bitmap bitmap = UserPortrait.DownloadSmallPortraint(m_NetAccount.UserName);
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, bitmap.RawFormat);
bitmap.Dispose();
Dispatcher.Invoke(new Action(() =>
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
Image1.Source = bi;
}));
}
catch (Exception ex)
{
UserClient.LogNet?.WriteException("Thread Download Portrait Failed", ex);
}
Image1.Source = AppWpfHelper.TranslateImageToBitmapImage(bitmap);
}));
}
}

View File

@@ -74,6 +74,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppWpfHelper.cs" />
<Compile Include="Views\AnotherCommandImplementation.cs" />
<Compile Include="Views\Controls\UserClientRenderItem.xaml.cs">
<DependentUpon>UserClientRenderItem.xaml</DependentUpon>