Skip to content

Commit

Permalink
Add gif export for Dress control, Animation control
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Jun 9, 2024
1 parent 008cbd3 commit 8b685a4
Show file tree
Hide file tree
Showing 4 changed files with 625 additions and 496 deletions.
46 changes: 32 additions & 14 deletions UoFiddler.Controls/UserControls/AnimationListControl.Designer.cs

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

62 changes: 57 additions & 5 deletions UoFiddler.Controls/UserControls/AnimationListControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using AnimatedGif;
using Ultima;
using UoFiddler.Controls.Classes;
using UoFiddler.Controls.Forms;
Expand Down Expand Up @@ -354,7 +355,6 @@ private int CurrentSelect

private void SetPicture()
{
_frames = null;
_mainPicture?.Dispose();
if (_currentSelect == 0)
{
Expand Down Expand Up @@ -484,8 +484,8 @@ private void OnPaint_MainPicture(object sender, PaintEventArgs e)
{
Point location = Point.Empty;
Size size = _mainPicture.Size;
location.X = (MainPictureBox.Width - _mainPicture.Width) / 2;
location.Y = (MainPictureBox.Height - _mainPicture.Height) / 2;
location.X = (MainPictureBox.Width / 2) - _frames[_frameIndex].Center.X;
location.Y = (MainPictureBox.Height / 2) - _frames[_frameIndex].Center.Y - _frames[_frameIndex].Bitmap.Height / 2;

Rectangle destRect = new Rectangle(location, size);

Expand All @@ -496,8 +496,7 @@ private void OnPaint_MainPicture(object sender, PaintEventArgs e)
_mainPicture = null;
}
}

private void TreeViewMobs_AfterSelect(object sender, TreeViewEventArgs e)
private void TreeViewMobs_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Parent != null)
{
Expand Down Expand Up @@ -1070,6 +1069,59 @@ private void ExportSingleFrame(ImageFormat imageFormat)
newBitmap.Save($"{fileName}-{(int)listView1.SelectedItems[0].Tag}.{fileExtension}", imageFormat);
}
}

private void ExportAnimatedGif(bool looping)
{
if (!Animate || _frames == null)
{
return;
}

var outputFile = Path.Combine(Options.OutputPath, $"{(_displayType == 1 ? "Equipment" : "Mob")} {_currentSelect}.gif");
var maxFrameSize = new Size(0, 0);

foreach (var frame in _frames)
{
maxFrameSize.Width = Math.Max(maxFrameSize.Width, frame.Bitmap.Width);
maxFrameSize.Height = Math.Max(maxFrameSize.Height, frame.Bitmap.Height);
}

{
using var gif = AnimatedGif.AnimatedGif.Create(outputFile, delay: 150);
foreach (var frame in _frames)
{
if (frame == null || frame.Bitmap == null)
{
continue;
}

using Bitmap target = new Bitmap(maxFrameSize.Width, maxFrameSize.Height);
using Graphics g = Graphics.FromImage(target);
g.DrawImage(frame.Bitmap, 0, 0);
gif.AddFrame(target, delay: -1, quality: GifQuality.Bit8);
}
}

if (!looping)
{
using var stream = new FileStream(outputFile, FileMode.Open, FileAccess.Write);
stream.Seek(28, SeekOrigin.Begin);
stream.WriteByte(0);
}

MessageBox.Show($"InGame Anim saved to {outputFile}", "Saved", MessageBoxButtons.OK,
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}

private void OnClickExtractAnimGifLooping(object sender, EventArgs e)
{
ExportAnimatedGif(true);
}

private void OnClickExtractAnimGifNoLooping(object sender, EventArgs e)
{
ExportAnimatedGif(false);
}
}

public class AlphaSorter : IComparer
Expand Down
Loading

0 comments on commit 8b685a4

Please sign in to comment.