sprite helper classes
This commit is contained in:
parent
83ee185c50
commit
a486f73046
5 changed files with 82 additions and 52 deletions
27
tanks-backend/TanksServer/Graphics/Sprite.cs
Normal file
27
tanks-backend/TanksServer/Graphics/Sprite.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal sealed class Sprite(bool?[,] data)
|
||||
{
|
||||
public static Sprite FromImageFile(string filePath)
|
||||
{
|
||||
using var image = Image.Load<Rgba32>(filePath);
|
||||
var data = new bool?[image.Width, image.Height];
|
||||
|
||||
var whitePixel = new Rgba32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
|
||||
for (var y = 0; y < image.Height; y++)
|
||||
for (var x = 0; x < image.Width; x++)
|
||||
{
|
||||
var pixelValue = image[x, y];
|
||||
data[x, y] = pixelValue.A == 0
|
||||
? null
|
||||
: pixelValue == whitePixel;
|
||||
}
|
||||
|
||||
return new Sprite(data);
|
||||
}
|
||||
|
||||
public bool? this[int x, int y] => data[x, y];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue