Skip to content
Snippets Groups Projects
Commit f8353f0e authored by Riley Mcgee's avatar Riley Mcgee
Browse files

Resize abstracted Out

parent d06920ae
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Transformation\TransformGif.cs" />
<Compile Include="View_Models\MainForm.cs"> <Compile Include="View_Models\MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -110,9 +111,7 @@ ...@@ -110,9 +111,7 @@
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Transformation\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2"> <BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
<Visible>False</Visible> <Visible>False</Visible>
......
...@@ -118,27 +118,27 @@ namespace Gifitti.Models ...@@ -118,27 +118,27 @@ namespace Gifitti.Models
/// </summary> /// </summary>
/// <param name="newWidth">New Width dimension in px.</param> /// <param name="newWidth">New Width dimension in px.</param>
/// <param name="newHeight">New Height dimension in px.</param> /// <param name="newHeight">New Height dimension in px.</param>
public void resizeGif(int newWidth, int newHeight) //public void resizeGif(int newWidth, int newHeight)
{ //{
using (MagickImageCollection collection = new MagickImageCollection()) // using (MagickImageCollection collection = new MagickImageCollection())
{ // {
for (int i = 0; i < frames.Length; i++) // for (int i = 0; i < frames.Length; i++)
{ // {
collection.Add(new MagickImage(frames[i] as Bitmap)); // collection.Add(new MagickImage(frames[i] as Bitmap));
collection[i].Resize(newWidth, newHeight); // collection[i].Resize(newWidth, newHeight);
} // }
// Optionally reduce colors // // Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings(); // QuantizeSettings settings = new QuantizeSettings();
settings.Colors = 256; // settings.Colors = 256;
collection.Quantize(settings); // collection.Quantize(settings);
// Optionally optimize the images (images should have the same size). // // Optionally optimize the images (images should have the same size).
collection.Optimize(); // collection.Optimize();
// Save gif // // Save gif
collection.Write("tempResize.gif"); // collection.Write("tempResize.gif");
} // }
} //}
/// <summary> /// <summary>
/// Fetches a sub gif over frames start -> stop /// Fetches a sub gif over frames start -> stop
...@@ -217,5 +217,10 @@ namespace Gifitti.Models ...@@ -217,5 +217,10 @@ namespace Gifitti.Models
return (Image)originalGif.Clone(); return (Image)originalGif.Clone();
//return a copy of it //return a copy of it
} }
public void SetFrameFromImage(Image frame, int index)
{
frames[index] = frame;
}
} }
} }
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");
}
}
}
}
...@@ -353,6 +353,7 @@ namespace Gifitti.View_Models ...@@ -353,6 +353,7 @@ namespace Gifitti.View_Models
//set the initial frames in textbox //set the initial frames in textbox
textBox1.Text = "0"; textBox1.Text = "0";
textBox2.Text = gm.numberOfFrames.ToString(); textBox2.Text = gm.numberOfFrames.ToString();
Transformation.TransformGif.resizeGif(this.gm, 100, 100);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment