mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
Use a better way to crop Sprite
This commit is contained in:
parent
d4060cde6d
commit
e501940f03
@ -197,7 +197,7 @@ namespace AssetStudio
|
|||||||
public Vector2 m_Offset;
|
public Vector2 m_Offset;
|
||||||
public Vector4 m_Border;
|
public Vector4 m_Border;
|
||||||
public float m_PixelsToUnits;
|
public float m_PixelsToUnits;
|
||||||
public Vector2 m_Pivot;
|
public Vector2 m_Pivot = new Vector2(0.5f, 0.5f);
|
||||||
public uint m_Extrude;
|
public uint m_Extrude;
|
||||||
public bool m_IsPolygon;
|
public bool m_IsPolygon;
|
||||||
public KeyValuePair<Guid, long> m_RenderDataKey;
|
public KeyValuePair<Guid, long> m_RenderDataKey;
|
||||||
|
@ -89,29 +89,25 @@ namespace AssetStudio
|
|||||||
var polygons = triangles.Select(x => new Polygon(new LinearLineSegment(x.Select(y => new PointF(y.X, y.Y)).ToArray()))).ToArray();
|
var polygons = triangles.Select(x => new Polygon(new LinearLineSegment(x.Select(y => new PointF(y.X, y.Y)).ToArray()))).ToArray();
|
||||||
IPathCollection path = new PathCollection(polygons);
|
IPathCollection path = new PathCollection(polygons);
|
||||||
var matrix = Matrix3x2.CreateScale(m_Sprite.m_PixelsToUnits);
|
var matrix = Matrix3x2.CreateScale(m_Sprite.m_PixelsToUnits);
|
||||||
var version = m_Sprite.version;
|
matrix *= Matrix3x2.CreateTranslation(m_Sprite.m_Rect.width * m_Sprite.m_Pivot.X - textureRectOffset.X, m_Sprite.m_Rect.height * m_Sprite.m_Pivot.Y - textureRectOffset.Y);
|
||||||
if (version[0] < 5
|
|
||||||
|| (version[0] == 5 && version[1] < 4)
|
|
||||||
|| (version[0] == 5 && version[1] == 4 && version[2] <= 1)) //5.4.1p3 down
|
|
||||||
{
|
|
||||||
matrix *= Matrix3x2.CreateTranslation(m_Sprite.m_Rect.width * 0.5f - textureRectOffset.X, m_Sprite.m_Rect.height * 0.5f - textureRectOffset.Y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
matrix *= Matrix3x2.CreateTranslation(m_Sprite.m_Rect.width * m_Sprite.m_Pivot.X - textureRectOffset.X, m_Sprite.m_Rect.height * m_Sprite.m_Pivot.Y - textureRectOffset.Y);
|
|
||||||
}
|
|
||||||
path = path.Transform(matrix);
|
path = path.Transform(matrix);
|
||||||
|
var graphicsOptions = new GraphicsOptions
|
||||||
|
{
|
||||||
|
Antialias = false,
|
||||||
|
AlphaCompositionMode = PixelAlphaCompositionMode.DestOut
|
||||||
|
};
|
||||||
var options = new DrawingOptions
|
var options = new DrawingOptions
|
||||||
{
|
{
|
||||||
GraphicsOptions = new GraphicsOptions()
|
GraphicsOptions = graphicsOptions
|
||||||
{
|
|
||||||
AlphaCompositionMode = PixelAlphaCompositionMode.DestOut
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
var rectP = new RectangularPolygon(0, 0, rect.Width, rect.Height);
|
using (var mask = new Image<Argb32>(rect.Width, rect.Height, SixLabors.ImageSharp.Color.Black))
|
||||||
spriteImage.Mutate(x => x.Fill(options, SixLabors.ImageSharp.Color.Red, rectP.Clip(path)));
|
{
|
||||||
spriteImage.Mutate(x => x.Flip(FlipMode.Vertical));
|
mask.Mutate(x => x.Fill(options, SixLabors.ImageSharp.Color.Red, path));
|
||||||
return spriteImage;
|
var bursh = new ImageBrush(mask);
|
||||||
|
spriteImage.Mutate(x => x.Fill(graphicsOptions, bursh));
|
||||||
|
spriteImage.Mutate(x => x.Flip(FlipMode.Vertical));
|
||||||
|
return spriteImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user