diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs index 8ae9d4732b6c02b21228261312b11b1e66655bd5..7497260d60d7559e159947233f85e1b168dbfcc9 100644 --- a/src/Gifitti/Gifitti/Models/GifModel.cs +++ b/src/Gifitti/Gifitti/Models/GifModel.cs @@ -70,17 +70,23 @@ namespace Gifitti.Models public void saveGif(string path) { //Error Handel on path - Regex savePathTest = new Regex(@"^(([^\/\\]+)[\/\\])*([^\/\\]*)\.[g|G][i|I][f|F]$"); - if (!savePathTest.IsMatch(path)) + + //RE for path with extension + Regex extensionTester = new Regex(@"^.*\.[g|G][i|I][f|F]$"); + //RE for path without extension + Regex savePathTester = new Regex(@"^(([^\/\\]+)[\/\\])*([^\/\\]*)"); + if (!savePathTester.IsMatch(path)) { throw new DirectoryNotFoundException(); } - + //Handel non gif extensions + if (!extensionTester.IsMatch(path)) + path += ".gif"; //TODO take in image setting components as well as frames being viewed etc. //Build GIF using (MagickImageCollection collection = new MagickImageCollection()) { - for (int i = 0; i < frames.Length; i++) + for (int i = this.startFrame; i < Math.Min(this.endFrame, frames.Length); i++) collection.Add(new MagickImage(frames[i] as Bitmap)); // Maximize Colour saturation diff --git a/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs b/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs index f2cf8fd9848584a48499ea5fa9619084526b4ada..dad8e3324014219f6c717ca3bbd1e1b8250e0ecf 100644 --- a/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs +++ b/src/Gifitti/Gifitti/View_Models/Form1.Designer.cs @@ -29,20 +29,18 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); this.openGifFileDialog = new System.Windows.Forms.OpenFileDialog(); this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); this.gifView = new System.Windows.Forms.PictureBox(); - this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components); this.meneFile = new System.Windows.Forms.MenuItem(); + this.menuOpenFile = new System.Windows.Forms.MenuItem(); this.menuFileExportAs = new System.Windows.Forms.MenuItem(); this.JPEG = new System.Windows.Forms.MenuItem(); this.PNG = new System.Windows.Forms.MenuItem(); this.BMP = new System.Windows.Forms.MenuItem(); this.TIFF = new System.Windows.Forms.MenuItem(); - + this.menuFileSaveAs = 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(); @@ -50,34 +48,10 @@ this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.timer1 = new System.Windows.Forms.Timer(this.components); - - this.menuFileSaveAs = new System.Windows.Forms.MenuItem(); this.saveGifFileDialog = new System.Windows.Forms.SaveFileDialog(); ((System.ComponentModel.ISupportInitialize)(this.gifView)).BeginInit(); this.SuspendLayout(); // - // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.button1.Location = new System.Drawing.Point(14, 632); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(156, 43); - this.button1.TabIndex = 0; - this.button1.Text = "Open GIF"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // button2 - // - this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.button2.Location = new System.Drawing.Point(484, 632); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(156, 43); - this.button2.TabIndex = 1; - this.button2.Text = "Save GIF"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); - // // openGifFileDialog // this.openGifFileDialog.FileName = "openGifFileDialog"; @@ -85,13 +59,13 @@ // // gifView // - this.gifView.Location = new System.Drawing.Point(14, 15); + this.gifView.Location = new System.Drawing.Point(12, 12); + this.gifView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.gifView.Name = "gifView"; - this.gifView.Size = new System.Drawing.Size(627, 609); + this.gifView.Size = new System.Drawing.Size(608, 470); this.gifView.TabIndex = 2; this.gifView.TabStop = false; // - // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { @@ -101,13 +75,20 @@ // this.meneFile.Index = 0; this.meneFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.menuOpenFile, this.menuFileExportAs, this.menuFileSaveAs}); this.meneFile.Text = "File"; // + // menuOpenFile + // + this.menuOpenFile.Index = 0; + this.menuOpenFile.Text = "Open..."; + this.menuOpenFile.Click += new System.EventHandler(this.MenuOpenFile); + // // menuFileExportAs // - this.menuFileExportAs.Index = 0; + this.menuFileExportAs.Index = 1; this.menuFileExportAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.JPEG, this.PNG, @@ -138,14 +119,21 @@ this.TIFF.Index = 3; this.TIFF.Text = "TIFF"; this.TIFF.Click += new System.EventHandler(this.MenuItemExportTIFF); - + // + // menuFileSaveAs + // + this.menuFileSaveAs.Index = 2; + this.menuFileSaveAs.Text = "Save as..."; + this.menuFileSaveAs.Click += new System.EventHandler(this.MenuItemFileSaveAs); + // // textBox1 // this.textBox1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.textBox1.Enabled = false; - this.textBox1.Location = new System.Drawing.Point(242, 524); + this.textBox1.Location = new System.Drawing.Point(285, 567); + this.textBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(32, 22); + this.textBox1.Size = new System.Drawing.Size(29, 22); this.textBox1.TabIndex = 3; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // @@ -153,9 +141,10 @@ // this.textBox2.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.textBox2.Enabled = false; - this.textBox2.Location = new System.Drawing.Point(291, 524); + this.textBox2.Location = new System.Drawing.Point(320, 567); + this.textBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox2.Name = "textBox2"; - this.textBox2.Size = new System.Drawing.Size(32, 22); + this.textBox2.Size = new System.Drawing.Size(29, 22); this.textBox2.TabIndex = 4; this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); // @@ -163,9 +152,10 @@ // this.button3.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.button3.Enabled = false; - this.button3.Location = new System.Drawing.Point(336, 506); + this.button3.Location = new System.Drawing.Point(355, 564); + this.button3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(75, 38); + this.button3.Size = new System.Drawing.Size(67, 30); this.button3.TabIndex = 5; this.button3.Text = "Stop"; this.button3.UseVisualStyleBackColor = true; @@ -175,7 +165,7 @@ // this.label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(240, 503); + this.label1.Location = new System.Drawing.Point(282, 548); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(38, 17); this.label1.TabIndex = 6; @@ -185,7 +175,7 @@ // this.label2.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(291, 504); + this.label2.Location = new System.Drawing.Point(319, 548); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(33, 17); this.label2.TabIndex = 7; @@ -195,7 +185,7 @@ // this.label3.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(170, 510); + this.label3.Location = new System.Drawing.Point(213, 561); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(66, 34); this.label3.TabIndex = 8; @@ -205,32 +195,20 @@ // this.timer1.Interval = 20; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); - - this.TIFF.Click += new System.EventHandler(this.MenuItemExportTIFF); - // - // menuFileSaveAs - // - this.menuFileSaveAs.Index = 1; - this.menuFileSaveAs.Text = "Save as..."; - this.menuFileSaveAs.Click += new System.EventHandler(this.MenuItemFileSaveAs); // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - + this.ClientSize = new System.Drawing.Size(632, 577); 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.ClientSize = new System.Drawing.Size(654, 691); - this.Controls.Add(this.gifView); - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Menu = this.mainMenu1; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -243,9 +221,6 @@ } #endregion - - private System.Windows.Forms.Button button1; - private System.Windows.Forms.Button button2; private System.Windows.Forms.OpenFileDialog openGifFileDialog; private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog; private System.Windows.Forms.PictureBox gifView; @@ -268,7 +243,7 @@ private System.Windows.Forms.MenuItem menuFileSaveAs; private System.Windows.Forms.SaveFileDialog saveGifFileDialog; - + private System.Windows.Forms.MenuItem menuOpenFile; } } diff --git a/src/Gifitti/Gifitti/View_Models/Form1.cs b/src/Gifitti/Gifitti/View_Models/Form1.cs index f28b180432b69b9076a2fc235cecf7177767698a..35f16dd0d92579ac51f6cefb98b3d3f5cec8814b 100644 --- a/src/Gifitti/Gifitti/View_Models/Form1.cs +++ b/src/Gifitti/Gifitti/View_Models/Form1.cs @@ -80,29 +80,6 @@ namespace Gifitti.View_Models } } - private void button2_Click(object sender, EventArgs e) - { - String x = ""; - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - x = folderBrowserDialog.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); - - } - } - #endregion #region SystemChecks private Boolean chkImage() @@ -255,12 +232,23 @@ namespace Gifitti.View_Models private void textBox1_TextChanged(object sender, EventArgs e) { - gm.startFrame = int.Parse(textBox1.Text); + int start = 0; + bool pass = int.TryParse(textBox1.Text, out start); + if (pass) + { + gm.startFrame = start; + } } private void textBox2_TextChanged(object sender, EventArgs e) { - gm.endFrame = int.Parse(textBox2.Text); + int end = 0; + bool pass = int.TryParse(textBox2.Text, out end); + if (pass) + { + gm.endFrame = end; + } + } private void MenuItemFileSaveAs(object sender, EventArgs e) @@ -292,5 +280,50 @@ namespace Gifitti.View_Models } #endregion + + private void MenuOpenFile(object sender, EventArgs e) + { + openGifFileDialog.Filter = "GIF Files|*.gif"; + DialogResult result = openGifFileDialog.ShowDialog(); // Show the dialog. + if (result == DialogResult.OK) // Test result. + { + string file = openGifFileDialog.FileName; + try + { + gm = new GifModel(file); + gm.ReverseAtEnd = false; + Image loadedGif = gm.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; + + //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(); + } + } } } diff --git a/src/Gifitti/Gifitti/View_Models/Form1.resx b/src/Gifitti/Gifitti/View_Models/Form1.resx index 54ea4780192382b0796e5fbf0eb0e34eaeb4c004..e5c92f7c580e3b84703aa9fc416bbb3bbf9d8b4f 100644 --- a/src/Gifitti/Gifitti/View_Models/Form1.resx +++ b/src/Gifitti/Gifitti/View_Models/Form1.resx @@ -126,10 +126,10 @@ <metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>452, 17</value> </metadata> - <metadata name="saveGifFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>611, 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> + <metadata name="saveGifFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>611, 17</value> + </metadata> </root> \ No newline at end of file