diff --git a/src/Gifitti/Gifitti/Form1.Designer.cs b/src/Gifitti/Gifitti/Form1.Designer.cs index dde6245bb170c3637661e5bf7a166e23192d7bfc..fd3ad1b8585483f6dbc407345c9b8e8fcbe4283e 100644 --- a/src/Gifitti/Gifitti/Form1.Designer.cs +++ b/src/Gifitti/Gifitti/Form1.Designer.cs @@ -28,11 +28,19 @@ /// </summary> private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); 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(); + 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); ((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit(); this.SuspendLayout(); // @@ -70,11 +78,84 @@ this.gifView.TabIndex = 2; this.gifView.TabStop = false; // + // 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); + // // 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.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); this.Controls.Add(this.gifView); this.Controls.Add(this.button2); this.Controls.Add(this.button1); @@ -84,6 +165,7 @@ this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gifView)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -94,6 +176,13 @@ private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; private System.Windows.Forms.PictureBox gifView; + 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; } } diff --git a/src/Gifitti/Gifitti/Form1.cs b/src/Gifitti/Gifitti/Form1.cs index 2ad201661bc1f349b3e1e9b369b7b064d4e9babe..15ca1b7c5470d60340a06a0c6099955c030243e0 100644 --- a/src/Gifitti/Gifitti/Form1.cs +++ b/src/Gifitti/Gifitti/Form1.cs @@ -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(); } } @@ -87,5 +99,37 @@ 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); + } } } diff --git a/src/Gifitti/Gifitti/Form1.resx b/src/Gifitti/Gifitti/Form1.resx index 1e80402ca6f54a45fc9f545bcdd84be37ee10528..e12a4a846e41f4a8b658ea52ea197b4a2807f445 100644 --- a/src/Gifitti/Gifitti/Form1.resx +++ b/src/Gifitti/Gifitti/Form1.resx @@ -123,4 +123,7 @@ <metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>184, 17</value> </metadata> + <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>388, 17</value> + </metadata> </root> \ No newline at end of file diff --git a/src/Gifitti/Gifitti/GifModel.cs b/src/Gifitti/Gifitti/GifModel.cs index 900c82e20de90a6b873668a4f8a2a224b1118559..a2539c7b567f6fdcf2d30e37f1e86676ad707101 100644 --- a/src/Gifitti/Gifitti/GifModel.cs +++ b/src/Gifitti/Gifitti/GifModel.cs @@ -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 + } } }