still fucked but less fucked
This commit is contained in:
parent
e06a1d9eb4
commit
8e53e37ce2
@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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,61 +17,42 @@ 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)!;
|
||||||
|
|
||||||
|
return await Task.Run(async () =>
|
||||||
|
{
|
||||||
Bitmap img1 = Resources.DefaultPfp;
|
Bitmap img1 = Resources.DefaultPfp;
|
||||||
Bitmap? img2 = null;
|
Bitmap? img2 = null;
|
||||||
Bitmap img3 = Resources.OfflineIcon;
|
Bitmap img3 = Resources.OfflineIcon;
|
||||||
|
|
||||||
var _pfpRes = await _apiService.GetUserProfilePic(userId);
|
var pfpRes = await pfpTask;
|
||||||
if (_pfpRes.Success && _pfpRes.Data != null)
|
if (pfpRes.Success && pfpRes.Data != null)
|
||||||
{
|
{
|
||||||
using var ms = new MemoryStream(_pfpRes.Data);
|
using var ms = new MemoryStream(pfpRes.Data);
|
||||||
img1 = (Bitmap)Image.FromStream(ms);
|
img1 = (Bitmap)Image.FromStream(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get cosmetic image
|
if (cosmeticStoreId > 0)
|
||||||
if (cosmeticStoreId >= 0)
|
|
||||||
{
|
{
|
||||||
var _storeRes = await _apiService.GetStoreItem(cosmeticStoreId);
|
var storeRes = await cosmeticTask;
|
||||||
if (_storeRes.Success && _storeRes.Data != null)
|
if (storeRes?.Success == true)
|
||||||
{
|
{
|
||||||
using var _http = new HttpClient();
|
using var httpRes = await _http.GetAsync(storeRes.Data?.AssetUrl);
|
||||||
using var _httpRes = await _http.GetAsync(_storeRes.Data.AssetUrl);
|
if (httpRes.IsSuccessStatusCode)
|
||||||
if (_httpRes.IsSuccessStatusCode)
|
|
||||||
{
|
{
|
||||||
var _imgByes = _httpRes.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult();
|
var bytes = await httpRes.Content.ReadAsByteArrayAsync();
|
||||||
using var ms = new MemoryStream(_imgByes);
|
using var ms = new MemoryStream(bytes);
|
||||||
img2 = (Bitmap?)Image.FromStream(ms);
|
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)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
img3 = Resources.OfflineIcon;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
img3 = Resources.OnlineIcon;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
img3 = Resources.AwayIcon;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
img3 = Resources.DNDIcon;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally, combine the images
|
|
||||||
Graphics g = Graphics.FromImage(combined);
|
|
||||||
g.Clear(Color.Transparent);
|
g.Clear(Color.Transparent);
|
||||||
g.CompositingMode = CompositingMode.SourceOver;
|
g.CompositingMode = CompositingMode.SourceOver;
|
||||||
|
|
||||||
g.DrawImage(img1, 4, 6, 128, 128);
|
g.DrawImage(img1, 4, 6, 128, 128);
|
||||||
|
|
||||||
if (img2 != null)
|
if (img2 != null)
|
||||||
@ -84,11 +63,20 @@ namespace qtcnet_client.Factories
|
|||||||
|
|
||||||
if (!int.IsNegative(status))
|
if (!int.IsNegative(status))
|
||||||
{
|
{
|
||||||
|
img3 = status switch
|
||||||
|
{
|
||||||
|
1 => Resources.OnlineIcon,
|
||||||
|
2 => Resources.AwayIcon,
|
||||||
|
3 => Resources.DNDIcon,
|
||||||
|
_ => Resources.OfflineIcon
|
||||||
|
};
|
||||||
|
|
||||||
img3.MakeTransparent();
|
img3.MakeTransparent();
|
||||||
g.DrawImage(img3, 104, 0, 35, 35);
|
g.DrawImage(img3, 104, 0, 35, 35);
|
||||||
}
|
}
|
||||||
|
|
||||||
return combined;
|
return combined;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Bitmap> GetStoreItemThumb(int id)
|
public async Task<Bitmap> GetStoreItemThumb(int id)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user