Skip to content
Snippets Groups Projects
Commit 3095176e authored by Nick Kozel's avatar Nick Kozel
Browse files

restoring project to old state

parent 40d849f8
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,10 @@
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.gifView = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit();
this.SuspendLayout();
//
// button1
......@@ -54,17 +58,31 @@
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// gifView
//
this.gifView.Location = new System.Drawing.Point(195, 197);
this.gifView.Name = "gifView";
this.gifView.Size = new System.Drawing.Size(100, 50);
this.gifView.TabIndex = 2;
this.gifView.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(582, 553);
this.Controls.Add(this.gifView);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.gifView)).EndInit();
this.ResumeLayout(false);
}
......@@ -73,6 +91,9 @@
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.PictureBox gifView;
}
}
......@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -12,6 +14,13 @@ namespace Gifitti
{
public partial class Form1 : Form
{
GifModel gm;
// GifImage _currentGif; <- used to encapsulate info later
private const int widthBuffer = 20;
private const int heightBuffer = 60;
Image globalGif;
public Form1()
{
InitializeComponent();
......@@ -24,12 +33,59 @@ namespace Gifitti
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "GIF Files|*.gif";
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
gm = new GifModel(file);
Image loadedGif = gm.gifImage.gifImage;
globalGif = loadedGif;
gifView.Image = loadedGif;
gifView.Width = loadedGif.Width;
gifView.Height = loadedGif.Height;
ClientSize = new Size(loadedGif.Width + widthBuffer, loadedGif.Height + heightBuffer);
}
catch (IOException)
{
}
CenterToScreen();
// Focus the gif:
gifView.Select();
gifView.Focus();
ActiveControl = gifView;
}
}
private void button2_Click(object sender, EventArgs e)
{
String x = "";
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
x = folderBrowserDialog1.SelectedPath;
}
List<Image> IMGs = new List<Image>();
Image test;
int Length = globalGif.GetFrameCount(FrameDimension.Time);
for (int i = 0; i < Length; i++)
{
globalGif.SelectActiveFrame(FrameDimension.Time, i);
test = new Bitmap(globalGif);
String y = "\\tmp-" + i + ".bmp";
String xy = x + y;
test.Save(@xy);
}
}
}
}
......@@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>184, 17</value>
</metadata>
</root>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gifitti
{
class GifImage
{
public Image gifImage
{
get; set;
}
private FrameDimension dimension;
private int frameCount;
private int currentFrame = -1;
private bool reverse;
private int step = 1;
public GifImage(string path)
{
gifImage = Image.FromFile(path);
//initialize
dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
//gets the GUID
//total frames in the animation
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
get { return reverse; }
set { reverse = value; }
}
public Image GetNextFrame()
{
currentFrame += step;
//if the animation reaches a boundary...
if (currentFrame >= frameCount || currentFrame < 1)
{
if (reverse)
{
step *= -1;
//...reverse the count
//apply it
currentFrame += step;
}
else
{
currentFrame = 0;
//...or start over
}
}
return GetFrame(currentFrame);
}
public Image GetFrame(int index)
{
gifImage.SelectActiveFrame(dimension, index);
//find the frame
return (Image)gifImage.Clone();
//return a copy of it
}
}
}
using ImageMagick;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gifitti
{
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");
}
}
}
}
......@@ -33,6 +33,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Magick.NET-Q16-AnyCPU, Version=7.0.0.0, Culture=neutral, PublicKeyToken=2004825badfa91ec, processorArchitecture=MSIL">
<HintPath>..\packages\Magick.NET-Q16-AnyCPU.7.0.3.502\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
......@@ -52,6 +56,8 @@
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="GifImage.cs" />
<Compile Include="GifModel.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
......@@ -66,6 +72,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>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Magick.NET-Q16-AnyCPU" version="7.0.3.502" targetFramework="net452" />
</packages>
\ No newline at end of file
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