diff --git a/src/Gifitti/Gifitti/Models/GifModel.cs b/src/Gifitti/Gifitti/Models/GifModel.cs index 0092f454f9660f53c0905f4804cdff9b28ddb088..fd6caa2b4f563cf6aa4b600eec2b9af4a6ea25fe 100644 --- a/src/Gifitti/Gifitti/Models/GifModel.cs +++ b/src/Gifitti/Gifitti/Models/GifModel.cs @@ -166,6 +166,7 @@ namespace Gifitti.Models } } + /// <summary> /// Whether the gif should play backwards when it reaches the end /// </summary> diff --git a/src/Gifitti/Gifitti/View_Models/MainForm.cs b/src/Gifitti/Gifitti/View_Models/MainForm.cs index 2aa7cba002cdafc2f0ae0955c6789396ca00e99b..c4eae65ff42acab454bbf36e2113b104e6f8cc5f 100644 --- a/src/Gifitti/Gifitti/View_Models/MainForm.cs +++ b/src/Gifitti/Gifitti/View_Models/MainForm.cs @@ -79,30 +79,7 @@ namespace Gifitti.View_Models /// <param name="e"> Event arguments associated with this event. </param> private void MenuItemExportJPEG(object sender, EventArgs e) { - if(chkImage()) - { - String x = ""; - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - x = folderBrowserDialog.SelectedPath; - } - - List<Image> IMGs = new List<Image>(); - Image test; - int Length = globalGif.GetFrameCount(FrameDimension.Time); - if (x != "") - { - for (int i = gm.startFrame; i < gm.endFrame; i++) - { - globalGif.SelectActiveFrame(FrameDimension.Time, i); - test = globalGif; - String y = "\\tmpj-" + i + ".jpg"; - String xy = x + y; - test.Save(@xy, ImageFormat.Jpeg); - } - } - } - + exportFrames(ImageFormat.Jpeg); } /// <summary> @@ -112,31 +89,17 @@ namespace Gifitti.View_Models /// <param name="e"> Event arguments associated with this event. </param> private void MenuItemExportPNG(object sender, EventArgs e) { - if (chkImage()) - { - String x = ""; - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - x = folderBrowserDialog.SelectedPath; - } - - List<Image> IMGs = new List<Image>(); - Image test; - int Length = globalGif.GetFrameCount(FrameDimension.Time); - if (x != "") - { - for (int i = gm.startFrame; i < gm.endFrame; i++) - { - globalGif.SelectActiveFrame(FrameDimension.Time, i); - test = globalGif; - String y = "\\tmpp-" + i + ".png"; - String xy = x + y; - test.Save(@xy, ImageFormat.Png); - } - } - } + exportFrames(ImageFormat.Png); } + private static Dictionary<ImageFormat, string> IMAGE_TO_EXTENSION = new Dictionary<ImageFormat, string>() + { + {ImageFormat.Bmp, "bmp" }, + {ImageFormat.Tiff, "tiff" }, + {ImageFormat.Jpeg, "jpeg" }, + {ImageFormat.Png, "png" } + }; + /// <summary> /// On event invocation the loaded gif is decomposed into its frames and saved to a specified folder as BMP (Bitmap) images. /// </summary> @@ -144,28 +107,24 @@ namespace Gifitti.View_Models /// <param name="e"> Event arguments associated with this event. </param> private void MenuItemExportBMP(object sender, EventArgs e) { - if (chkImage()) - { - String x = ""; - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - x = folderBrowserDialog.SelectedPath; - } + exportFrames(ImageFormat.Bmp); + } - List<Image> IMGs = new List<Image>(); - Image test; - int Length = globalGif.GetFrameCount(FrameDimension.Time); - if (x != "") - { - for (int i = gm.startFrame; i < gm.endFrame; i++) - { - globalGif.SelectActiveFrame(FrameDimension.Time, i); - test = new Bitmap(globalGif); - String y = "\\tmpb-" + i + ".bmp"; - String xy = x + y; - test.Save(@xy); - } - } + + public void exportFrames(ImageFormat format) + { + if (!chkImage()) + return; + + String path = ""; + if (folderBrowserDialog.ShowDialog() == DialogResult.OK) + path = folderBrowserDialog.SelectedPath; + + + for (int i = 0; i < gm.numberOfFrames; i++) + { + var a = gm.GetFrame(i); + a.Save(path + @"\frame" + i + @"." + IMAGE_TO_EXTENSION[format], format); } } @@ -176,29 +135,7 @@ namespace Gifitti.View_Models /// <param name="e"> Event arguments associated with this event. </param> private void MenuItemExportTIFF(object sender, EventArgs e) { - if (chkImage()) - { - String x = ""; - if (folderBrowserDialog.ShowDialog() == DialogResult.OK) - { - x = folderBrowserDialog.SelectedPath; - } - - List<Image> IMGs = new List<Image>(); - Image test; - int Length = globalGif.GetFrameCount(FrameDimension.Time); - if (x != "") - { - for (int i = gm.startFrame; i < gm.endFrame; i++) - { - globalGif.SelectActiveFrame(FrameDimension.Time, i); - test = globalGif; - String y = "\\tmpt-" + i + ".tiff"; - String xy = x + y; - test.Save(@xy, ImageFormat.Tiff); - } - } - } + exportFrames(ImageFormat.Tiff); } /// <summary> @@ -352,10 +289,10 @@ namespace Gifitti.View_Models //set the initial frames in textbox textBox1.Text = "0"; - textBox2.Text = gm.numberOfFrames.ToString(); + textBox2.Text = gm.numberOfFrames.ToString(); //TODO: remove tem } - } + } /// <summary> /// Loads the Help Menu Form. /// </summary>