diff --git a/src/Gifitti/Gifitti/Gifitti.csproj b/src/Gifitti/Gifitti/Gifitti.csproj index 2ec85293efd15c904abf26e345918471a529d275..06268b13edbfbbde35c1429eb5a8992bf5b955da 100644 --- a/src/Gifitti/Gifitti/Gifitti.csproj +++ b/src/Gifitti/Gifitti/Gifitti.csproj @@ -66,6 +66,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="Transformation\TransformGif.cs" /> <Compile Include="View_Models\MainForm.cs"> <SubType>Form</SubType> </Compile> @@ -110,9 +111,7 @@ <ItemGroup> <None Include="App.config" /> </ItemGroup> - <ItemGroup> - <Folder Include="Transformation\" /> - </ItemGroup> + <ItemGroup /> <ItemGroup> <BootstrapperPackage Include=".NETFramework,Version=v4.5.2"> <Visible>False</Visible> diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs index b8636cf520b62736d1c9a1f300c8161fcbffba42..652a5c6a3ddcd5fa57132533a760b356c23acaa3 100644 --- a/src/Gifitti/Gifitti/Models/GifModel.cs +++ b/src/Gifitti/Gifitti/Models/GifModel.cs @@ -118,27 +118,27 @@ namespace Gifitti.Models /// </summary> /// <param name="newWidth">New Width dimension in px.</param> /// <param name="newHeight">New Height dimension in px.</param> - public void resizeGif(int newWidth, int newHeight) - { - using (MagickImageCollection collection = new MagickImageCollection()) - { - for (int i = 0; i < frames.Length; i++) - { - collection.Add(new MagickImage(frames[i] as Bitmap)); - collection[i].Resize(newWidth, newHeight); - } - // Optionally reduce colors - QuantizeSettings settings = new QuantizeSettings(); - settings.Colors = 256; - collection.Quantize(settings); - - // Optionally optimize the images (images should have the same size). - collection.Optimize(); - - // Save gif - collection.Write("tempResize.gif"); - } - } + //public void resizeGif(int newWidth, int newHeight) + //{ + // using (MagickImageCollection collection = new MagickImageCollection()) + // { + // for (int i = 0; i < frames.Length; i++) + // { + // collection.Add(new MagickImage(frames[i] as Bitmap)); + // collection[i].Resize(newWidth, newHeight); + // } + // // Optionally reduce colors + // QuantizeSettings settings = new QuantizeSettings(); + // settings.Colors = 256; + // collection.Quantize(settings); + + // // Optionally optimize the images (images should have the same size). + // collection.Optimize(); + + // // Save gif + // collection.Write("tempResize.gif"); + // } + //} /// <summary> /// Fetches a sub gif over frames start -> stop @@ -217,5 +217,10 @@ namespace Gifitti.Models return (Image)originalGif.Clone(); //return a copy of it } + + public void SetFrameFromImage(Image frame, int index) + { + frames[index] = frame; + } } } diff --git a/src/Gifitti/Gifitti/Transformation/TransformGif.cs b/src/Gifitti/Gifitti/Transformation/TransformGif.cs new file mode 100644 index 0000000000000000000000000000000000000000..6353d47396bf01491a9450dc9f76078f3bbca448 --- /dev/null +++ b/src/Gifitti/Gifitti/Transformation/TransformGif.cs @@ -0,0 +1,47 @@ +using Gifitti.Models; +using ImageMagick; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gifitti.Transformation +{ + /// <summary> + /// Methods for GIF transformations kept together + /// </summary> + static class TransformGif + { + /// <summary> + /// Resizes a GIF to be newWidth x newHeight px + /// </summary> + /// <param name="newWidth">New Width dimension in px.</param> + /// <param name="newHeight">New Height dimension in px.</param> + /// <param name="gm" cref="GifModel">GifModel being modified.</param> + public static void resizeGif(GifModel gm, int newWidth, int newHeight) + { + using (MagickImageCollection collection = new MagickImageCollection()) + { + for (int i = 0; i < gm.numberOfFrames; i++) + { + collection.Add(new MagickImage(gm.GetFrame(i) as Bitmap)); + collection[i].Resize(newWidth, newHeight); + gm.SetFrameFromImage(collection[i].ToBitmap(), i); + } + // Optionally reduce colors + //QuantizeSettings settings = new QuantizeSettings(); + //settings.Colors = 256; + //collection.Quantize(settings); + + //// Optionally optimize the images (images should have the same size). + //collection.Optimize(); + + //// Save gif + //collection.Write("tempResize.gif"); + + } + } + } +} diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.cs b/src/Gifitti/Gifitti/View_Models/MainForm.cs index 2aa7cba002cdafc2f0ae0955c6789396ca00e99b..9ad3ad1fe9106ee473e3da3ec3575162d2e92e38 100644 --- a/src/Gifitti/Gifitti/View_Models/MainForm.cs +++ b/src/Gifitti/Gifitti/View_Models/MainForm.cs @@ -353,6 +353,7 @@ namespace Gifitti.View_Models //set the initial frames in textbox textBox1.Text = "0"; textBox2.Text = gm.numberOfFrames.ToString(); + Transformation.TransformGif.resizeGif(this.gm, 100, 100); } }