mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-22 23:35:30 +00:00
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using System.Drawing;
|
|
using AnimatedGif;
|
|
|
|
namespace PckStudio.Core.Extensions
|
|
{
|
|
public static class AnimationExtensions
|
|
{
|
|
public static Image CreateAnimationImage(this Animation animation) => animation.CreateAnimationImage(Color.Black);
|
|
|
|
public static Image CreateAnimationImage(this Animation animation, Color blendColor)
|
|
{
|
|
if (animation.FrameCount == 0)
|
|
{
|
|
return null;
|
|
}
|
|
var ms = new System.IO.MemoryStream();
|
|
var generateor = new AnimatedGifCreator(ms, GameConstants.GAMETICK_IN_MILLISECONDS, 0);
|
|
foreach (Animation.Frame frame in animation.GetInterpolatedFrames())
|
|
{
|
|
Image texture = (blendColor == Color.Black || blendColor == Color.White) ? frame.Texture : frame.Texture.Blend(blendColor, BlendMode.Multiply);
|
|
generateor.AddFrame(texture, frame.Ticks * GameConstants.GAMETICK_IN_MILLISECONDS, GifQuality.Bit8);
|
|
}
|
|
ms.Position = 0;
|
|
return Image.FromStream(ms);
|
|
}
|
|
}
|
|
}
|