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

adding playback features closes 8 closes 9

parents 2dea6af3 6ffca4c1
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.gifView = new System.Windows.Forms.PictureBox();
<<<<<<< HEAD
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
......@@ -41,6 +42,15 @@
this.PNG = new System.Windows.Forms.MenuItem();
this.BMP = new System.Windows.Forms.MenuItem();
this.TIFF = new System.Windows.Forms.MenuItem();
=======
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
>>>>>>> playback
((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit();
this.SuspendLayout();
//
......@@ -81,6 +91,7 @@
this.gifView.TabIndex = 2;
this.gifView.TabStop = false;
//
<<<<<<< HEAD
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
......@@ -126,12 +137,90 @@
this.TIFF.Index = 3;
this.TIFF.Text = "TIFF";
this.TIFF.Click += new System.EventHandler(this.menuItem6_Click);
=======
// textBox1
//
this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(242, 524);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(32, 22);
this.textBox1.TabIndex = 3;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.textBox2.Enabled = false;
this.textBox2.Location = new System.Drawing.Point(291, 524);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(32, 22);
this.textBox2.TabIndex = 4;
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// button3
//
this.button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.button3.Enabled = false;
this.button3.Location = new System.Drawing.Point(336, 506);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 38);
this.button3.TabIndex = 5;
this.button3.Text = "Stop";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label1
//
this.label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(240, 503);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 17);
this.label1.TabIndex = 6;
this.label1.Text = "Start";
//
// label2
//
this.label2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(291, 504);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(33, 17);
this.label2.TabIndex = 7;
this.label2.Text = "End";
//
// label3
//
this.label3.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(170, 510);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(66, 34);
this.label3.TabIndex = 8;
this.label3.Text = "Frame \r\nSelection";
//
// timer1
//
this.timer1.Interval = 20;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
>>>>>>> playback
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
<<<<<<< HEAD
this.ClientSize = new System.Drawing.Size(436, 449);
=======
this.ClientSize = new System.Drawing.Size(582, 553);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
>>>>>>> playback
this.Controls.Add(this.gifView);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
......@@ -143,6 +232,7 @@
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.gifView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
......@@ -153,6 +243,7 @@
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.PictureBox gifView;
<<<<<<< HEAD
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
......@@ -160,6 +251,15 @@
private System.Windows.Forms.MenuItem PNG;
private System.Windows.Forms.MenuItem BMP;
private System.Windows.Forms.MenuItem TIFF;
=======
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Timer timer1;
>>>>>>> playback
}
}
......@@ -41,11 +41,11 @@ namespace Gifitti
try
{
gm = new GifModel(file);
Image loadedGif = gm.gifImage.gifImage;
gm.ReverseAtEnd = false;
Image loadedGif = Image.FromFile(file);
globalGif = loadedGif;
gifView.Image = loadedGif;
//gifView.Image = loadedGif;
gifView.Width = loadedGif.Width;
gifView.Height = loadedGif.Height;
......@@ -58,10 +58,22 @@ namespace Gifitti
CenterToScreen();
// Focus the gif:
//Focus the gif:
gifView.Select();
gifView.Focus();
ActiveControl = gifView;
//Start Animating
timer1.Enabled = true;
//Enable frame selection
textBox1.Enabled = true;
textBox2.Enabled = true;
button3.Enabled = true;
//set the initial frames in textbox
textBox1.Text = "0";
textBox2.Text = gm.numberOfFrames.ToString();
}
}
......@@ -88,6 +100,7 @@ namespace Gifitti
}
}
<<<<<<< HEAD
private Boolean chkImage()
{
Boolean check = true;
......@@ -210,6 +223,38 @@ namespace Gifitti
}
}
}
=======
private void button3_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
button3.Text = "Start";
gifView.Enabled = false;
timer1.Enabled = false;
}
else
{
button3.Text = "Stop";
gifView.Enabled = true;
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//get next frame
gifView.Image = gm.GetNextFrame();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
gm.startFrame = int.Parse(textBox1.Text);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
gm.endFrame = int.Parse(textBox2.Text);
>>>>>>> playback
}
}
}
......@@ -123,7 +123,12 @@
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>184, 17</value>
</metadata>
<<<<<<< HEAD
<metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>353, 17</value>
=======
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>388, 17</value>
>>>>>>> playback
</metadata>
</root>
\ No newline at end of file
......@@ -11,49 +11,38 @@ namespace Gifitti
{
class GifModel
{
public GifImage gifImage { get; private set; }
public Image originalGif { get; private set; }
private int numberOfFrames;
private FrameDimension dimension;
public int numberOfFrames { get; private set; }
private Image[] frames;
private int step = 1;
private int currentFrame = -1;
private bool reverse;
public int startFrame = 0;
public int endFrame = 0;
//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);
}
//constructor
public GifModel(String path)
{
this.gifImage = new GifImage(path);
//Save the original Gif
originalGif = this.gifImage.gifImage.Clone() as Image;
frameConstruction(this.gifImage);
originalGif = Image.FromFile(path);
dimension = new FrameDimension(originalGif.FrameDimensionsList[0]);
frameConstruction(originalGif);
}
//Construct Frames for the entire Image
private void frameConstruction(GifImage gifImage)
private void frameConstruction(Image originalImg)
{
numberOfFrames = gifImage.gifImage.GetFrameCount(FrameDimension.Time);
numberOfFrames = originalImg.GetFrameCount(FrameDimension.Time);
endFrame = numberOfFrames;
frames = new Image[numberOfFrames];
for (int i = 0; i < numberOfFrames; i++)
for(int i = 0; i < numberOfFrames; i++)
{
originalGif.SelectActiveFrame(FrameDimension.Time, i);
frames[i] = originalGif.Clone() as Image;
frames[i] = ((Image)originalGif.Clone());
}
}
public void resetToOriginalGif()
{
gifImage.gifImage = originalGif;
}
public void resizeGif(int newWidth, int newHeight)
{
using (MagickImageCollection collection = new MagickImageCollection())
......@@ -74,9 +63,6 @@ namespace Gifitti
// Save gif
collection.Write("tempResize.gif");
}
}
public void returnSubGif(int start, int stop)
......@@ -101,5 +87,44 @@ namespace Gifitti
collection.Write("temp.gif");
}
}
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 >= numberOfFrames || currentFrame < 1 || currentFrame >= endFrame)
{
if (reverse)
{
step *= -1;
//...reverse the count
//apply it
currentFrame += step;
}
else
{
currentFrame = startFrame;
//...or start over
}
}
return GetFrame(currentFrame);
}
public Image GetFrame(int index)
{
originalGif.SelectActiveFrame(dimension, index);
//find the frame
return (Image)originalGif.Clone();
//return a copy of it
}
}
}
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