private void comboBoxResolution_DropDown(object sender, EventArgs e) { ComboBox comboBox = (ComboBox)sender; int cells = 0; try { cells = Convert.ToInt32(textBoxCells.Text); } catch { MessageBox.Show("Input count of cells first"); return; } if (isChangedCells) { if (CurrentImage != null) { try { labelWaitResolution.Text = "Wait..."; labelWaitResolution.Refresh(); try { using (Bitmap image = new Bitmap(CurrentImage)) { embroideryService = EmbroideryService.GetEmbroideryService(Properties.Settings.Default.AddressOfService); resolutions = embroideryService.PossibleResolutions(image, cells, 2, 10);//Count of resolutions here <-----------| embroideryService.Close(); } } catch (OutOfMemoryException ex) { MessageBox.Show("Input image is too large"); labelWaitResolution.Text = ""; return; } catch (Exception ex) { MessageBox.Show("Occurred some exception. Try set less or more count of cells"); labelWaitResolution.Text = ""; return; } foreach (var item in resolutions) comboBoxResolution.Items.Add(item.Key); isChangedCells = false; labelWaitResolution.Text = ""; labelWaitResolution.Refresh(); } catch(Exception ex) { labelWaitResolution.Text = ""; MessageBox.Show("Incorrect data: " + ex.Message); return; } } else { MessageBox.Show("Open image first"); return; } } }
private void buttonCreateEmbroidery_Click(object sender, EventArgs e) { #region Exceptions if(CurrentImage == null) { MessageBox.Show("Open any image first!"); return; } int cellsCount = 0; try { cellsCount = Convert.ToInt32(textBoxCells.Text); } catch { MessageBox.Show("Count of cells is wrong"); return; } if (cellsCount == 0) { MessageBox.Show("Choose Count of squares"); return; } List<Char> symbols = new List<char>(); foreach (var item in textBoxes) { try { symbols.Add(Convert.ToChar(item.Text)); } catch { MessageBox.Show("Sumbols data is incorrext"); return; } } if (comboBoxResolution.SelectedItem == null) { MessageBox.Show("Choose resolution"); return; } Color[] palette = this.GetColorsFromPanel(); if (palette == null) { MessageBox.Show("Choose palette"); return; } resultLabel.Text = "Loading..."; resultLabel.Refresh(); int ratio; resolutions.TryGetValue((string)comboBoxResolution.SelectedItem, out ratio); char[] masSymbols = null; masSymbols = new char[symbols.Count]; int i = 0; foreach (var item in symbols) masSymbols[i++] = item; if (palette.Length > masSymbols.Length) masSymbols = null; NSEmbroidery.UI.Embroidery.GridType type = NSEmbroidery.UI.Embroidery.GridType.None; if (checkBoxGrid.CheckState == CheckState.Checked) { if (radioButtonPoints.Checked) type = NSEmbroidery.UI.Embroidery.GridType.Points; else if (radioButtonLine.Checked) type = NSEmbroidery.UI.Embroidery.GridType.SolidLine; } #endregion /*--------------------using service here-------------------------------------------------*/ string uri = Properties.Settings.Default.AddressOfService; embroideryService = EmbroideryService.GetEmbroideryService(uri); Embroidery embroideryDelegate = new Embroidery(embroideryService.GetEmbroidery); try { Bitmap image = new Bitmap(CurrentImage); Stopwatch watch = new Stopwatch(); watch.Start(); IAsyncResult asuncResult = embroideryDelegate.BeginInvoke(image, ratio, cellsCount, new System.Drawing.Color[]{System.Drawing.Color.Black, System.Drawing.Color.White, System.Drawing.Color.Red}, masSymbols, SymbolColor, type, null, null); Bitmap resultImage = embroideryDelegate.EndInvoke(asuncResult); watch.Stop(); labelResolutionImage.Text = "Time spent: "; labelResolutionImage.Text += watch.ElapsedMilliseconds.ToString(); labelResolutionImage.Refresh(); embroideryService.Close(); ResultImage imageForm = new ResultImage(); imageForm.Image = new Bitmap(resultImage); resultLabel.Text = ""; imageForm.ShowDialog(); } catch (Exception ex) { MessageBox.Show("Resolution that was choosed is too large"); resultLabel.Text = ""; return; } /*---------------------------------------------------------------------------------------*/ }