Implement CreateProfileImage
To Combine Precense Icon, Profile Image, and Cosmetic To Make Final Profile Image
This commit is contained in:
parent
00df7505a7
commit
446745d4df
20
qtc-net-client-2/Forms/Profile.Designer.cs
generated
20
qtc-net-client-2/Forms/Profile.Designer.cs
generated
@ -37,13 +37,11 @@
|
||||
btnDecline = new Button();
|
||||
btnCancelRequest = new Button();
|
||||
btnMessage = new Button();
|
||||
pbUserStatus = new PictureBox();
|
||||
pbCurrencyIcon = new PictureBox();
|
||||
lblCurrencyAmount = new Label();
|
||||
flpUsernameCurrency = new FlowLayoutPanel();
|
||||
pCurrency = new Panel();
|
||||
((System.ComponentModel.ISupportInitialize)pbUserPfp).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pbUserStatus).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pbCurrencyIcon).BeginInit();
|
||||
flpUsernameCurrency.SuspendLayout();
|
||||
pCurrency.SuspendLayout();
|
||||
@ -52,9 +50,9 @@
|
||||
// pbUserPfp
|
||||
//
|
||||
pbUserPfp.Image = Properties.Resources.DefaultPfp;
|
||||
pbUserPfp.Location = new Point(13, 11);
|
||||
pbUserPfp.Location = new Point(9, 5);
|
||||
pbUserPfp.Name = "pbUserPfp";
|
||||
pbUserPfp.Size = new Size(128, 128);
|
||||
pbUserPfp.Size = new Size(139, 138);
|
||||
pbUserPfp.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
pbUserPfp.TabIndex = 2;
|
||||
pbUserPfp.TabStop = false;
|
||||
@ -148,17 +146,6 @@
|
||||
btnMessage.Visible = false;
|
||||
btnMessage.Click += btnMessage_Click;
|
||||
//
|
||||
// pbUserStatus
|
||||
//
|
||||
pbUserStatus.BackColor = Color.Transparent;
|
||||
pbUserStatus.Image = Properties.Resources.OfflineIcon;
|
||||
pbUserStatus.Location = new Point(115, 1);
|
||||
pbUserStatus.Name = "pbUserStatus";
|
||||
pbUserStatus.Size = new Size(32, 32);
|
||||
pbUserStatus.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||
pbUserStatus.TabIndex = 10;
|
||||
pbUserStatus.TabStop = false;
|
||||
//
|
||||
// pbCurrencyIcon
|
||||
//
|
||||
pbCurrencyIcon.Image = Properties.Resources.CurrencyIcon;
|
||||
@ -213,7 +200,6 @@
|
||||
Controls.Add(btnAccept);
|
||||
Controls.Add(btnDecline);
|
||||
Controls.Add(btnCancelRequest);
|
||||
Controls.Add(pbUserStatus);
|
||||
Controls.Add(btnAddContact);
|
||||
Controls.Add(rtxtBio);
|
||||
Controls.Add(pbUserPfp);
|
||||
@ -230,7 +216,6 @@
|
||||
FormClosed += Profile_FormClosed;
|
||||
Load += frmProfile_Load;
|
||||
((System.ComponentModel.ISupportInitialize)pbUserPfp).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pbUserStatus).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pbCurrencyIcon).EndInit();
|
||||
flpUsernameCurrency.ResumeLayout(false);
|
||||
flpUsernameCurrency.PerformLayout();
|
||||
@ -249,7 +234,6 @@
|
||||
private Button btnDecline;
|
||||
private Button btnCancelRequest;
|
||||
private Button btnMessage;
|
||||
private PictureBox pbUserStatus;
|
||||
private PictureBox pbCurrencyIcon;
|
||||
private Label lblCurrencyAmount;
|
||||
private FlowLayoutPanel flpUsernameCurrency;
|
||||
|
@ -51,58 +51,44 @@ namespace qtc_net_client_2.Forms
|
||||
lblCurrencyAmount.Text = _userInformationDto.CurrencyAmount.ToString("N0");
|
||||
rtxtBio.Text = _userInformationDto.Bio;
|
||||
|
||||
pbUserPfp.Location = new(13, 11);
|
||||
pbUserPfp.Size = new(128, 128);
|
||||
|
||||
Bitmap? pfp = null;
|
||||
if (pfpRes != null && pfpRes.Success && pfpRes.Data != null)
|
||||
{
|
||||
using (var ms = new MemoryStream(pfpRes.Data))
|
||||
{
|
||||
pbUserPfp.Image = new Bitmap(ms);
|
||||
pfp = new Bitmap(ms);
|
||||
}
|
||||
}
|
||||
|
||||
var userStatus = (UserStatus)_userInformationDto.Status;
|
||||
Bitmap precenseImage = Resources.OnlineIcon;
|
||||
switch (userStatus)
|
||||
{
|
||||
case UserStatus.Online:
|
||||
pbUserStatus.Image = Resources.OnlineIcon;
|
||||
precenseImage = Resources.OnlineIcon;
|
||||
break;
|
||||
case UserStatus.Away:
|
||||
pbUserStatus.Image = Resources.AwayIcon;
|
||||
precenseImage = Resources.AwayIcon;
|
||||
break;
|
||||
case UserStatus.DoNotDisturb:
|
||||
pbUserStatus.Image = Resources.DNDIcon;
|
||||
precenseImage = Resources.DNDIcon;
|
||||
break;
|
||||
case UserStatus.Offline:
|
||||
pbUserStatus.Image = Resources.OfflineIcon;
|
||||
precenseImage = Resources.OfflineIcon;
|
||||
break;
|
||||
}
|
||||
|
||||
Bitmap? cosmetic = null;
|
||||
if(cosmeticRes != null)
|
||||
{
|
||||
using var ms = new MemoryStream(cosmeticRes);
|
||||
CombineProfileImageWithCosmetic(pbUserPfp.Image, new Bitmap(ms));
|
||||
cosmetic = new Bitmap(ms);
|
||||
}
|
||||
|
||||
if (_userInformationDto.ProfileCosmeticId != 0)
|
||||
{
|
||||
var res = await _apiService.GetStoreItem(_userInformationDto.ProfileCosmeticId);
|
||||
if (res != null && res.Success && res.Data != null)
|
||||
{
|
||||
var client = new HttpClient();
|
||||
var response = await client.GetAsync(res.Data.AssetUrl);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
{
|
||||
|
||||
}
|
||||
response.Dispose();
|
||||
}
|
||||
client.Dispose();
|
||||
}
|
||||
}
|
||||
CreateProfileImage(precenseImage, pfp, cosmetic);
|
||||
precenseImage.Dispose();
|
||||
pfp?.Dispose();
|
||||
cosmetic?.Dispose();
|
||||
|
||||
if (_userInformationDto.Id == _apiService.CurrentUser!.Id)
|
||||
{
|
||||
@ -253,22 +239,30 @@ namespace qtc_net_client_2.Forms
|
||||
frmDirectMessage.Show();
|
||||
}
|
||||
|
||||
private void CombineProfileImageWithCosmetic(Image pfp, Bitmap cosmetic)
|
||||
private void CreateProfileImage(Bitmap precenseImage, Bitmap? pfp = null, Bitmap? cosmetic = null)
|
||||
{
|
||||
cosmetic.MakeTransparent();
|
||||
Bitmap combined = new Bitmap(139, 138);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(combined))
|
||||
{
|
||||
g.Clear(Color.Transparent);
|
||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
||||
using Graphics g = Graphics.FromImage(combined);
|
||||
g.Clear(Color.Transparent);
|
||||
g.CompositingMode = CompositingMode.SourceOver;
|
||||
|
||||
if (pfp != null)
|
||||
{
|
||||
pfp.MakeTransparent();
|
||||
g.DrawImage(pfp, 4, 6, 128, 128);
|
||||
}
|
||||
else g.DrawImage(pbUserPfp.Image, 4, 6, 128, 128);
|
||||
|
||||
if (cosmetic != null)
|
||||
{
|
||||
cosmetic.MakeTransparent();
|
||||
g.DrawImage(cosmetic, 0, 0, 139, 138);
|
||||
}
|
||||
|
||||
pbUserPfp.Location = new(9, 5);
|
||||
pbUserPfp.Size = new(139, 138);
|
||||
precenseImage.MakeTransparent();
|
||||
g.DrawImage(precenseImage, 104, 0, 35, 35);
|
||||
|
||||
pbUserPfp.Image = combined;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user