Skip to content

Commit

Permalink
Add Export to GIF
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Jun 3, 2024
1 parent 4ef75b0 commit 4bdcbb8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
1 change: 1 addition & 0 deletions UoFiddler.Controls/UoFiddler.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,6 @@
<ItemGroup>
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
<PackageReference Include="AnimatedGif" Version="1.0.5" />
</ItemGroup>
</Project>
46 changes: 31 additions & 15 deletions UoFiddler.Controls/UserControls/AnimDataControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions UoFiddler.Controls/UserControls/AnimDataControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using AnimatedGif;
using Ultima;
using UoFiddler.Controls.Classes;
using UoFiddler.Controls.Forms;
Expand Down Expand Up @@ -748,6 +750,40 @@ private void OnClick_Hue(object sender, EventArgs e)
_showForm.TopMost = true;
_showForm.Show();
}

private void OnClick_ExportAsGif(object sender, EventArgs e)
{
if (_selAnimdataEntry != null)
{
var outputFile = Path.Combine(Options.OutputPath, $"AnimData 0x{_currAnim:X}.gif");
var delay = (100 * _selAnimdataEntry.FrameInterval) + 1;

{
using var gif = AnimatedGif.AnimatedGif.Create(outputFile, delay);
if (_customHue > 0)
{
// Not in a lock, since event runs on main thread, which is the only place it can be written.
foreach (var huedFrame in _huedFrames)
{
if (huedFrame != null)
{
gif.AddFrame(huedFrame, delay: -1, quality: GifQuality.Bit8);
}
}
}
else
{
for (int i = 0; i < _selAnimdataEntry.FrameCount; ++i)
{
int graphic = _currAnim + _selAnimdataEntry.FrameData[i];
gif.AddFrame(Art.GetStatic(graphic), delay: -1, quality: GifQuality.Bit8);
}
}
}

MessageBox.Show($"Saved to {outputFile}");
}
}
}

public class AnimdataSorter : IComparer
Expand Down

0 comments on commit 4bdcbb8

Please sign in to comment.