public bool ChangePortrait(BitmapImage portrait) { try { var postdata = $"credit={UserData.credit}&portrait={ToolUtil.BytesToHex(ToolUtil.BitmapImageToBytes(portrait))}"; var result = JsonConvert.DeserializeObject <ResponceModel <_E_Result> >(HttpUtil.post(API[APIKey.SetInfo], postdata)); if (result.code == 200 && result.data.e_portrait == 2) { UserData.Portrait = portrait; UserData.userstate = Data.UserState.Success; MessageInvoked?.Invoke(this, new MessageEventArgs("changeportrait", "修改用户头像成功")); return(true); } UserData.userstate = Data.UserState.Waring; MessageInvoked?.Invoke(this, new MessageEventArgs("changportrait", result.msg)); return(false); } catch (Exception ex) { MessageInvoked?.Invoke(this, new MessageEventArgs("changeportrait", $"修改用户头像失败 {ex.Message}")); return(false); } }