コード例 #1
0
        private void LoadToGrid(string fileName)
        {
            try {
                List <Resolution> result = JsonWriteLoad.LoadJson(_fileName).OrderBy(x => x.Width).ToList();

                dataGridView1.DataSource = result;

                label4.Text = "Total Resolutions : " + result.Count();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        private void CallFromTaskTestWorker()
        {
            try
            {
                ProgressIndex = 0;
                foreach (var f in files)
                {
                    FileInfo fileInfo = new FileInfo(f);
                    string   ext      = fileInfo.Extension.ToLower();

                    if (ext == ".jpg" || ext == ".png")
                    {
                        listBox1.Items.Add(f);
                    }
                }

                if (listBox1.Items.Count > 0)
                {
                    // lable1 is for percentage
                    //progressbar for progress of converting

                    List <Models.Resolution> results = JsonWriteLoad.LoadJson(_fileName);
                    total = listBox1.Items.Count * results.Count();

                    ProgressCompleteGlobal = 0f;

                    progressBar1.Maximum = total * 100 / total + 1;


                    label4.Text = "Total selected images " + listBox1.Items.Count.ToString() + "  Images Produced  : " + total;



                    if (!worker.IsBusy)
                    {
                        worker.RunWorkerAsync();
                    }
                }
                else
                {
                    string message = " Images not found please try again !";
                    listBox1.Items.Add(message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
 private void LoadImages(string fileName)
 {
     try
     {
         Settings settings = new Settings();
         settings          = JsonWriteLoad.LoadJsonSettings(fileName);
         textBox1.Text     = Convert.ToString(settings.PPI);
         comboBox1.Text    = Convert.ToString(settings.ImageType);
         trackBar1.Value   = (int)settings.Quality;
         checkBox1.Checked = settings.PreserveAspectRatio;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #4
0
        private void EditContent()
        {
            try
            {
                if (currentSelection2 != null)
                {
                    List <Resolution> result = JsonWriteLoad.LoadJson(_fileName);



                    int first = currentSelection2.Width;
                    int last  = currentSelection2.Height;
                    int index = result.FindIndex(x => x.Width == currentSelection2.Width && x.Height == currentSelection2.Height);
                    int.TryParse(textBox1.Text, out first);
                    int.TryParse(textBox2.Text, out last);
                    result[index].Width    = first;
                    result[index].Height   = last;
                    result[index].IsActive = currentSelection2.IsActive;
                    JsonWriteLoad.WriteJson(_fileName, result);

                    LoadToGrid(_fileName);
                    element           = -1;
                    currentSelection2 = null;
                    if (currentSelection2 == null)
                    {
                        button3.Enabled = false;
                    }
                    StringBuilder str = new StringBuilder();
                    str.Append("Total Resolutions : ");
                    str.Append(dataGridView1.Rows.Count);
                    label4.Text = str.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int w = -1;
                int h = -1;

                int.TryParse(textBox1.Text, out w);
                int.TryParse(textBox2.Text, out h);
                if (w > 20 && h > 20)
                {
                    List <Resolution> result = JsonWriteLoad.LoadJson(_fileName);

                    Resolution r = new Resolution();
                    r.Width  = w;
                    r.Height = h;
                    if (result.FindIndex(x => x.Width == r.Width && x.Height == r.Height) < 0)
                    {
                        result.Add(r);
                        JsonWriteLoad.WriteJson(_fileName, result);
                        LoadToGrid(_fileName);
                    }
                    else
                    {
                        MessageBox.Show("Resolution Already Exists!");
                    }
                }
                else
                {
                    MessageBox.Show("Please Enter Valid Resolution!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #6
0
 private void saveSettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         Settings settings = new Settings();
         float    ppi      = 150;
         float.TryParse(textBox1.Text, out ppi);
         string defJPG = null;
         if (comboBox1.SelectedItem == null)
         {
             defJPG = ".jpg";
         }
         else
         {
             defJPG = comboBox1.SelectedItem.ToString();
         }
         settings.Initialize(ppi, trackBar1.Value, checkBox1.Checked, defJPG);
         JsonWriteLoad.WriteJsonSettings(@"Saved_Settings.json", settings);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #7
0
        private void CallWorkerPerThread(BackgroundWorker worker, int startingPoint, int endPoint, int totalImagesSelected)
        {
            try
            {
                DateTime timeStart = DateTime.Now;
                List <Models.Resolution> results = JsonWriteLoad.LoadJson(_fileName);


                int currentIndex = startingPoint;

                int indexFromBack    = totalImagesSelected - 1;
                int currentIncrement = 0;

                //endPoint is not used yet
                while (currentIndex < totalImagesSelected)
                {
                    for (int res = 0, resBack = results.Count() - 1; res < results.Count(); res++, resBack--)
                    {
                        if (resBack <= res)
                        {
                            break;
                        }

                        int totalCircles        = ResizeImageToSpecificSize(currentIncrement, listBox1.Items[currentIndex].ToString(), DestinationToSave, ImageQuality, results[res].Width, results[res].Height);
                        int totalCircleFromBack = ResizeImageToSpecificSize(currentIncrement, listBox1.Items[indexFromBack].ToString(), DestinationToSave, ImageQuality, results[resBack].Width, results[resBack].Height);

                        if (totalCircles > totalCircleFromBack)
                        {
                            currentIncrement = totalCircles;
                        }
                        else if (totalCircles < totalCircleFromBack)
                        {
                            currentIncrement = totalCircleFromBack;
                        }
                        else
                        {
                            currentIncrement = totalCircles;
                        }

                        //MessageBox.Show("TC : " + totalCircles.ToString() + " TCFB : " + totalCircleFromBack.ToString());
                        int percentage = currentIncrement * 2 * 100 / total;
                        worker.ReportProgress(percentage);
                    }

                    currentIndex++;
                }


                int finalPercentage = currentIncrement * 2 * 100 / total;

                worker.ReportProgress(finalPercentage);
                DateTime timeEnd = DateTime.Now;
                TimeSpan diff    = timeEnd - timeStart;
                threadStart         = new ThreadStart(() => DelegateInvoke(diff.TotalSeconds.ToString()));
                thread              = new Thread(threadStart);
                thread.IsBackground = true;
                thread.Start();
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unhandled Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }