/// <summary> /// 发送图片 /// </summary> private async void SendImage() { if (UserModel != null && SelectedFriend != null) { UserModel user = UserModel; UserModel friend = SelectedFriend; OpenFileDialog openImage = new OpenFileDialog(); openImage.Title = "上传图片"; openImage.Filter = "图片|*.jpg;*.png"; if (openImage.ShowDialog() == true) { string cachePath = Config.GetUserDirectory(user.UserName, Config.CacheDirectoryName); string imagePath = $"{cachePath}\\{DateTime.Now.ToString("yyyyMMddHHmmss")}{Path.GetExtension(openImage.SafeFileName)}"; if (ClientHelper.AutoCutPicture(openImage.FileName, imagePath)) { if (await Config.MiniClient.SendImageAsync(friend.UserName, imagePath)) { SaveMessageRecord(friend.UserName, new MessageModel() { Source = new UserModel() { UserName = user.UserName, NickName = "Me" }, Image = imagePath }); UpdateMessageList(); return; } MessageBox.Show("提交时发生异常,发送失败!", Config.Name, MessageBoxButton.OK, MessageBoxImage.Error); } } } }