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

Added resizing of Gifs to export and export of sub gifs

parent d66b76b1
No related branches found
No related tags found
No related merge requests found
Showing
with 18946 additions and 22 deletions
No preview for this file type
......@@ -6,11 +6,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gifitti
namespace Gifitti.GifImageModule
{
public class GifImage
{
private Image gifImage;
public Image gifImage
{
get; set;
}
private FrameDimension dimension;
private int frameCount;
private int currentFrame = -1;
......@@ -27,6 +30,16 @@ namespace Gifitti
frameCount = gifImage.GetFrameCount(dimension);
}
private void modifyGifImage(Image gif)
{
gifImage = gif;
//initialize
dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
//gets the GUID
//total frames in the animation
frameCount = gifImage.GetFrameCount(dimension);
}
public bool ReverseAtEnd
{
//whether the gif should play backwards when it reaches the end
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using ImageMagick;
namespace Gifitti.GifImageModule
{
public class GifModel
{
public GifImage gifImage { get; private set; }
public Image originalGif { get; private set; }
private int numberOfFrames;
private Image[] frames;
//Build a Gif Model instace
//Re create object when a new gif is loaded
//Keep when working with same gif
public GifModel(GifImage gifImage)
{
this.gifImage = gifImage;
//Save the original Gif
originalGif = this.gifImage.gifImage.Clone() as Image;
frameConstruction(this.gifImage);
}
public GifModel(String path)
{
this.gifImage = new GifImage(path);
//Save the original Gif
originalGif = this.gifImage.gifImage.Clone() as Image;
frameConstruction(this.gifImage);
}
//Construct Frames for the entire Image
private void frameConstruction(GifImage gifImage)
{
numberOfFrames = gifImage.gifImage.GetFrameCount(FrameDimension.Time);
frames = new Image[numberOfFrames];
for (int i = 0; i < numberOfFrames; i++)
{
originalGif.SelectActiveFrame(FrameDimension.Time, i);
frames[i] = originalGif.Clone() as Image;
}
}
public void resetToOriginalGif()
{
gifImage.gifImage = originalGif;
}
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 returnSubGif(int start, int stop)
{
using (MagickImageCollection collection = new MagickImageCollection())
{
// Add first image and set the animation delay to 100ms
for (int i = start; i < stop; i++)
{
collection.Add(new ImageMagick.MagickImage(frames[i] as Bitmap));
collection[i - start].AnimationDelay = 1;
}
// 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("temp.gif");
}
}
}
}
......@@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......@@ -34,6 +36,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-x86, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=x86">
<HintPath>..\packages\Magick.NET-Q16-x86.7.0.3.300\lib\net40-client\Magick.NET-Q16-x86.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -45,19 +52,21 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Views\Form1.cs">
<Compile Include="GifImageModule\GifModel.cs" />
<Compile Include="Views\MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Views\Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="Views\MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="GifImage.cs" />
<Compile Include="GifImageModule\GifImage.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Views\Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="Views\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
......@@ -68,6 +77,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......@@ -82,6 +92,13 @@
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Magick.NET-Q16-x86.7.0.3.300\build\net40-client\Magick.NET-Q16-x86.targets" Condition="Exists('..\packages\Magick.NET-Q16-x86.7.0.3.300\build\net40-client\Magick.NET-Q16-x86.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Magick.NET-Q16-x86.7.0.3.300\build\net40-client\Magick.NET-Q16-x86.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Magick.NET-Q16-x86.7.0.3.300\build\net40-client\Magick.NET-Q16-x86.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
......@@ -15,10 +15,13 @@ namespace Gifitti
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainForm());
GifImageModule.GifModel gm = new GifImageModule.GifModel("C:/Users/riley_000/Desktop/GIFS/giphy.gif");
gm.resizeGif(700, 700);
}
}
}
namespace Gifitti.Views
{
partial class Form1
partial class MainForm
{
/// <summary>
/// Required designer variable.
......@@ -31,6 +31,7 @@
this.button1 = new System.Windows.Forms.Button();
this.gifView = new System.Windows.Forms.PictureBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit();
this.SuspendLayout();
//
......@@ -54,21 +55,33 @@
this.gifView.Size = new System.Drawing.Size(684, 476);
this.gifView.TabIndex = 1;
this.gifView.TabStop = false;
this.gifView.Click += new System.EventHandler(this.gifView_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// Form1
// button2
//
this.button2.Location = new System.Drawing.Point(564, 502);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(134, 52);
this.button2.TabIndex = 2;
this.button2.Text = "Export half gif";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(711, 566);
this.Controls.Add(this.button2);
this.Controls.Add(this.gifView);
this.Controls.Add(this.button1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.Name = "Form1";
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
......@@ -82,6 +95,7 @@
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox gifView;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button button2;
}
}
......@@ -8,17 +8,21 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Gifitti.GifImageModule;
namespace Gifitti.Views
{
public partial class Form1 : Form
public partial class MainForm : Form
{
GifModel gm;
// GifImage _currentGif; <- used to encapsulate info later
private const int widthBuffer = 20;
private const int heightBuffer = 60;
public Form1()
public MainForm()
{
InitializeComponent();
}
......@@ -31,8 +35,8 @@ namespace Gifitti.Views
string file = openFileDialog1.FileName;
try
{
Image loadedGif = Image.FromFile(file);
gifView.Image = loadedGif;
gm = new GifModel(file);
Image loadedGif = gm.gifImage.gifImage;
gifView.Width = loadedGif.Width;
gifView.Height = loadedGif.Height;
ClientSize = new Size(loadedGif.Width+widthBuffer, loadedGif.Height+heightBuffer);
......@@ -42,7 +46,7 @@ namespace Gifitti.Views
{
}
CenterToScreen();
CenterToScreen();
// Focus the gif:
gifView.Select();
......@@ -55,5 +59,15 @@ namespace Gifitti.Views
{
}
private void gifView_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
gm?.returnSubGif(1,10);
}
}
}
No preview for this file type
This diff is collapsed.
src/Gifitti/Gifitti/bin/Debug/Snakeware.Animated.gif

378 KiB

src/Gifitti/Gifitti/bin/Debug/tempResize.gif

3.68 MiB

No preview for this file type
......@@ -8,11 +8,14 @@ C:\Users\nicol\Documents\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.csproj.Ge
C:\Users\nicol\Documents\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.exe
C:\Users\nicol\Documents\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.pdb
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Gifitti.exe.config
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.pdb
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Gifitti.exe
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Gifitti.pdb
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.csprojResolveAssemblyReference.cache
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.Views.MainForm.resources
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.Properties.Resources.resources
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.csproj.GenerateResource.Cache
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.exe
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.Views.Form1.resources
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.pdb
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\obj\Debug\Gifitti.csprojResolveAssemblyReference.cache
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Magick.NET-Q16-x86.Native.dll
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Magick.NET-Q16-x86.dll
C:\Code\C_Sharp\Gifitti\src\Gifitti\Gifitti\bin\Debug\Magick.NET-Q16-x86.xml
No preview for this file type
No preview for this file type
No preview for this file type
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bumpkit" version="1.0.2" targetFramework="net452" />
<package id="Magick.NET-Q16-x86" version="7.0.3.300" targetFramework="net452" />
</packages>
\ No newline at end of file
File added
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