mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-17 05:30:48 +08:00
🎨 IcoTest
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
@@ -1,3 +1,4 @@
|
||||
using DynamicData;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace BD.WTTS.UnitTest;
|
||||
@@ -55,30 +56,29 @@ public sealed class IcoTest
|
||||
}
|
||||
}
|
||||
|
||||
//static IEnumerable<int> G(int size, int[] dw)
|
||||
//{
|
||||
// foreach (var item in dw)
|
||||
// {
|
||||
// if (item <= size) yield return item;
|
||||
// }
|
||||
//}
|
||||
|
||||
[Test]
|
||||
public void CreateShortcutIcon()
|
||||
{
|
||||
var logo512Path = Path.Combine(ProjectUtils.ProjPath, "res", "icons", "app", "v3", "Logo_512.png");
|
||||
var gameicoPath = Path.Combine(ProjectUtils.ProjPath, "res", "avatars", "gameicos", "origin.png");
|
||||
var imgDirInfo = new DirectoryInfo(Path.Combine(ProjectUtils.ProjPath, "res", "avatars"));
|
||||
|
||||
using var logo512Bitmap = SKBitmap.Decode(logo512Path);
|
||||
using var gameBitmap = SKBitmap.Decode(gameicoPath);
|
||||
|
||||
var gear = new[] { 512, 256, 128, 96, 64, 48, 32, 24, 16 };
|
||||
var saveDirPath = Path.Combine(assemblyDir, "avatars");
|
||||
IOPath.DirCreateByNotExists(saveDirPath);
|
||||
|
||||
foreach (var img in imgDirInfo.GetFiles())
|
||||
{
|
||||
SKBitmap[]? bitmaps = null;
|
||||
using var imgBitmap = SKBitmap.Decode(img.FullName);
|
||||
|
||||
using var fBitmap = ResizeImage(imgBitmap, logo512Bitmap);
|
||||
|
||||
bitmaps = new[] { fBitmap }.Concat(new[] { 256, 128, 96, 64, 48, 32, 24, 16 }
|
||||
var allSize = GetImgResolutionPower(imgBitmap.Width, gear);
|
||||
var maxSize = allSize.Max();
|
||||
using var fBitmap = ResizeImage(imgBitmap, gameBitmap, maxSize);
|
||||
bitmaps = new[] { fBitmap }.Concat(allSize.Where(x => x != maxSize)
|
||||
.Select(x => fBitmap.Resize(new SKSizeI { Height = x, Width = x }, SKFilterQuality.High)))
|
||||
.ToArray();
|
||||
|
||||
@@ -91,23 +91,34 @@ public sealed class IcoTest
|
||||
FileShare.ReadWrite | FileShare.Delete);
|
||||
IcoEncoder.Encode(fs, bitmaps);
|
||||
TestContext.WriteLine(savePath);
|
||||
|
||||
if (bitmaps != null)
|
||||
bitmaps.ForEach(x => x.Dispose());
|
||||
}
|
||||
}
|
||||
|
||||
static SKBitmap ResizeImage(SKBitmap image, SKBitmap icoIcon)
|
||||
static SKBitmap ResizeImage(SKBitmap image, SKBitmap icoIcon, int size)
|
||||
{
|
||||
int icoWidth = icoIcon.Width / 4;
|
||||
int icoHeight = icoIcon.Height / 4;
|
||||
int watermarkLeft = icoIcon.Width - icoWidth;
|
||||
int watermarkTop = icoIcon.Height - icoHeight;
|
||||
int icoWidth = size / 4;
|
||||
int icoHeight = size / 4;
|
||||
|
||||
SKBitmap scaledImage = new(icoIcon.Width, icoIcon.Height);
|
||||
int watermarkLeft = size - icoWidth;
|
||||
int watermarkTop = size - icoHeight;
|
||||
|
||||
SKBitmap scaledImage = new(size, size);
|
||||
image.ScalePixels(scaledImage, SKFilterQuality.High);
|
||||
|
||||
using SKCanvas canvas = new(scaledImage);
|
||||
using SKPaint paint = new();
|
||||
paint.Color = paint.Color.WithAlpha(10);
|
||||
canvas.DrawBitmap(icoIcon, new SKRect(watermarkLeft, watermarkTop, watermarkLeft + icoWidth, watermarkTop + icoHeight), paint);
|
||||
canvas.DrawBitmap(icoIcon, new SKRect(watermarkLeft, watermarkTop, watermarkLeft + icoWidth, watermarkTop + icoHeight));
|
||||
return scaledImage;
|
||||
}
|
||||
|
||||
static IEnumerable<int> GetImgResolutionPower(int size, int[] rp)
|
||||
{
|
||||
foreach (var item in rp)
|
||||
{
|
||||
if (item <= size) yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user