still fucked but less fucked

This commit is contained in:
Alan Moon 2025-12-11 17:03:27 -08:00
parent e06a1d9eb4
commit 8e53e37ce2
2 changed files with 52 additions and 64 deletions

View File

@ -210,7 +210,7 @@ namespace QtCNETAPI.Services.ApiService
{ {
var restRequest = new RestRequest($"users/profile-pic/{userId}") var restRequest = new RestRequest($"users/profile-pic/{userId}")
.AddHeader("Authorization", $"Bearer {SessionToken}"); .AddHeader("Authorization", $"Bearer {SessionToken}");
var response = await _client.GetAsync(restRequest); var response = await _client.GetAsync(restRequest).ConfigureAwait(false);
if (response != null) if (response != null)
{ {

View File

@ -1,17 +1,15 @@
using QtCNETAPI.Models; using qtcnet_client.Properties;
using QtCNETAPI.Models;
using QtCNETAPI.Schema;
using QtCNETAPI.Services.ApiService; using QtCNETAPI.Services.ApiService;
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using Microsoft.Extensions.FileProviders;
using qtcnet_client.Properties;
namespace qtcnet_client.Factories namespace qtcnet_client.Factories
{ {
public class ImageFactory public class ImageFactory
{ {
private readonly IApiService _apiService; private readonly IApiService _apiService;
private readonly HttpClient _http = new();
public ImageFactory(IApiService apiService) public ImageFactory(IApiService apiService)
{ {
_apiService = apiService; _apiService = apiService;
@ -19,76 +17,66 @@ namespace qtcnet_client.Factories
public async Task<Bitmap> GetAndCreateProfileImage(string userId, int status = -1, int cosmeticStoreId = 0) public async Task<Bitmap> GetAndCreateProfileImage(string userId, int status = -1, int cosmeticStoreId = 0)
{ {
Bitmap combined = new(139, 138); var pfpTask = _apiService.GetUserProfilePic(userId);
var cosmeticTask = cosmeticStoreId >= 0 ? _apiService.GetStoreItem(cosmeticStoreId) : Task.FromResult<ServiceResponse<StoreItem>?>(null)!;
Bitmap img1 = Resources.DefaultPfp; return await Task.Run(async () =>
Bitmap? img2 = null;
Bitmap img3 = Resources.OfflineIcon;
var _pfpRes = await _apiService.GetUserProfilePic(userId);
if (_pfpRes.Success && _pfpRes.Data != null)
{ {
using var ms = new MemoryStream(_pfpRes.Data); Bitmap img1 = Resources.DefaultPfp;
img1 = (Bitmap)Image.FromStream(ms); Bitmap? img2 = null;
} Bitmap img3 = Resources.OfflineIcon;
// get cosmetic image var pfpRes = await pfpTask;
if (cosmeticStoreId >= 0) if (pfpRes.Success && pfpRes.Data != null)
{
var _storeRes = await _apiService.GetStoreItem(cosmeticStoreId);
if (_storeRes.Success && _storeRes.Data != null)
{ {
using var _http = new HttpClient(); using var ms = new MemoryStream(pfpRes.Data);
using var _httpRes = await _http.GetAsync(_storeRes.Data.AssetUrl); img1 = (Bitmap)Image.FromStream(ms);
if (_httpRes.IsSuccessStatusCode) }
if (cosmeticStoreId > 0)
{
var storeRes = await cosmeticTask;
if (storeRes?.Success == true)
{ {
var _imgByes = _httpRes.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); using var httpRes = await _http.GetAsync(storeRes.Data?.AssetUrl);
using var ms = new MemoryStream(_imgByes); if (httpRes.IsSuccessStatusCode)
img2 = (Bitmap?)Image.FromStream(ms); {
var bytes = await httpRes.Content.ReadAsByteArrayAsync();
using var ms = new MemoryStream(bytes);
img2 = (Bitmap)Image.FromStream(ms);
}
} }
} }
}
// set status image Bitmap combined = new(139, 138);
if (!int.IsNegative(status)) using var g = Graphics.FromImage(combined);
{
switch (status) g.Clear(Color.Transparent);
g.CompositingMode = CompositingMode.SourceOver;
g.DrawImage(img1, 4, 6, 128, 128);
if (img2 != null)
{ {
case 0: img2.MakeTransparent();
img3 = Resources.OfflineIcon; g.DrawImage(img2, 0, 0, 139, 138);
break;
case 1:
img3 = Resources.OnlineIcon;
break;
case 2:
img3 = Resources.AwayIcon;
break;
case 3:
img3 = Resources.DNDIcon;
break;
} }
}
// finally, combine the images if (!int.IsNegative(status))
Graphics g = Graphics.FromImage(combined); {
g.Clear(Color.Transparent); img3 = status switch
g.CompositingMode = CompositingMode.SourceOver; {
1 => Resources.OnlineIcon,
2 => Resources.AwayIcon,
3 => Resources.DNDIcon,
_ => Resources.OfflineIcon
};
g.DrawImage(img1, 4, 6, 128, 128); img3.MakeTransparent();
g.DrawImage(img3, 104, 0, 35, 35);
}
if (img2 != null) return combined;
{ });
img2.MakeTransparent();
g.DrawImage(img2, 0, 0, 139, 138);
}
if (!int.IsNegative(status))
{
img3.MakeTransparent();
g.DrawImage(img3, 104, 0, 35, 35);
}
return combined;
} }
public async Task<Bitmap> GetStoreItemThumb(int id) public async Task<Bitmap> GetStoreItemThumb(int id)