/// <summary> Changes your avatar. </summary> /// <remarks>Only supports PNG and JPEG (see AvatarImageType)</remarks> public async Task ChangeAvatar(AvatarImageType imageType, byte[] bytes, string currentEmail, string currentPassword) { CheckReady(); var response = await _api.ChangeAvatar(imageType, bytes, currentEmail, currentPassword); _users.Update(response.Id, response); }
public Task <SelfUserInfo> ChangeAvatar(AvatarImageType imageType, byte[] bytes, string currentEmail, string currentPassword) { string base64 = Convert.ToBase64String(bytes); string type = imageType == AvatarImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64"; var request = new APIRequests.ChangeAvatar { Avatar = $"data:{type},/9j/{base64}", CurrentEmail = currentEmail, CurrentPassword = currentPassword }; return(_http.Patch <SelfUserInfo>(Endpoints.UserMe, request)); }
public static ImageProvider _createImageProvider(AvatarImageType imageType, string _imagePath) { ImageProvider tmp_ImageProvider = null; switch (imageType) { case AvatarImageType.NetWork: tmp_ImageProvider = new NetworkImage(_imagePath); break; case AvatarImageType.Asset: tmp_ImageProvider = new AssetImage(_imagePath); break; case AvatarImageType.Memory: byte[] bytes = File.ReadAllBytes(_imagePath); tmp_ImageProvider = new MemoryImage(bytes: bytes); break; } return(tmp_ImageProvider); }
//Profile public Task<EditProfileResponse> EditProfile(string currentPassword = "", string username = null, string email = null, string password = null, AvatarImageType avatarType = AvatarImageType.Png, byte[] avatar = null) { if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword)); string avatarBase64 = null; if (avatarType == AvatarImageType.None) avatarBase64 = ""; else if (avatar != null) { string base64 = Convert.ToBase64String(avatar); string type = avatarType == AvatarImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64"; avatarBase64 = $"data:{type},{base64}"; } var request = new EditProfileRequest { CurrentPassword = currentPassword, Username = username, Email = email, Password = password, Avatar = avatarBase64 }; return _rest.Patch<EditProfileResponse>(Endpoints.UserMe, request); }
public Task<SelfUserInfo> ChangeAvatar(AvatarImageType imageType, byte[] bytes, string currentEmail, string currentPassword) { string base64 = Convert.ToBase64String(bytes); string type = imageType == AvatarImageType.Jpeg ? "image/jpeg;base64" : "image/png;base64"; var request = new APIRequests.ChangeAvatar { Avatar = $"data:{type},/9j/{base64}", CurrentEmail = currentEmail, CurrentPassword = currentPassword }; return _http.Patch<SelfUserInfo>(Endpoints.UserMe, request); }
//Profile public Task<EditProfileResponse> EditProfile(string currentPassword = "", string username = null, string email = null, string password = null, AvatarImageType avatarType = AvatarImageType.Png, byte[] avatar = null) { if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword)); return _api.EditProfile(currentPassword: currentPassword, username: username, email: email, password: password, avatarType: avatarType, avatar: avatar); }