Exemple #1
0
 /// <summary>
 /// Upload settings file and parse it
 /// </summary>
 /// <returns>
 /// return a settings object
 /// </returns>
 public static Settings GetSettings()
 {
     if (!CheckSettingsHealth())
     {
         SetUpSettings();
         const string alertText = "Settings file was corrupted, please, check settings.";
         var alertDlg = new AlertDialog(alertText);
         alertDlg.Show();
     }
     return ReadSettings();
 }
 public int GetPalletRange()
 {
     try
     {
         return Settings.ColorPallet;
     }
     catch (NullReferenceException e)
     {
         // TODO: Exception check needed, can't send null to MainPageController to draw temp-color pallet
         // TODO: Start new thread to repair settings file
         var alert = new AlertDialog("Cannot get settings. Please check settings file.");
         alert.Show();
         return 8;
     }
 }
        /// <summary>
        /// Starts solve process
        /// </summary>
        private void onSolveClick(object sender, RoutedEventArgs args)
        {
            if (_isPictureLoaded == false || _areaList.Count == 0)
            {
                var aD = new AlertDialog("Изображение не загружено или нет выделенных областей.");
                aD.Show();
                return;
            }

            var controller = new SolverController(_areaList, Bitmap.BitsPerPix);
            controller.Solve();

            var solvedWindow = new Results()
                                   {
                                       ResultSquares = controller.GetResultSquares(),
                                       Temps = GetTempList() };
            solvedWindow.Activate();
            solvedWindow.Show();
        }
 private void OnRectSelectChecked(object sender, RoutedEventArgs args)
 {
     if (!_isPictureLoaded)
     {
         RectSelect.IsChecked = false;
         var alertDlg = new AlertDialog("Изображение не загружено.");
         alertDlg.Show();
         return;
     }
     AddArea.IsEnabled = true;
     RectSelector.IsEnabled = true;
 }
        private void OnAddAreaClick(object sender, RoutedEventArgs args)
        {
            if (RectSelector.SelectedArea == null)
            {
                const string str = "Область не выбрана.";
                var alert = new AlertDialog(str);
                alert.Show();
                return;
            }

            var newArea = GetSelectedAreaImage(Bitmap.BmSource, RectSelector.StartPos, RectSelector.EndPos);
            if (newArea == null)
                return;

            var area = new Area();
            foreach (var p in newArea)
            {
                area.Points.Add((byte) p);
            }
            area.Name = "Область " + _index;
            area.AreaID = _index;
            if (_areaList.Count == 0)
                area.Main = true;
            _areaList.Add(area);
            OnAreaListUpdate();
            _index++;
        }
        private Array GetSelectedAreaImage(BitmapSource bitmap, Point a, Point b)
        {
            CheckSizeOfArea(bitmap, a, b, out a, out b);
            if (a.X == 0 && a.Y == 0 && b.X == 0 && b.Y == 0)
                return null;
            //from StackOverflow
            // stride must be a number of bits? for buffer to copy the selected area
            //var stride = bitmap.PixelWidth * (bitmap.Format.BitsPerPixel / 8);
            var stride = (int) (Math.Abs((b.X - a.X))*(bitmap.Format.BitsPerPixel/8));

            //var length = bitmap.PixelHeight * stride;
            var length = (int) (Math.Abs((b.Y - a.Y)) * stride);

            //int length = (int)(((b.X - a.X) * (b.Y - a.Y) + 1) * bitmap.Format.BitsPerPixel);// + 100000);
            //int stride = (bitmap.PixelWidth *
            //              bitmap.Format.BitsPerPixel + 7) / 8;
            //Array newbitmap = new byte[length];
            Array newbitmap = new byte[length];
            var rect = new Int32Rect((int) a.X, (int) a.Y, (int)(b.X - a.X), (int)(b.Y - a.Y));
            try
            {
                bitmap.CopyPixels(rect, newbitmap, stride, 0);
            }
            catch (Exception e)
            {
                var alertDlg = new AlertDialog("Произошла ошибка " + e.ToString());
                alertDlg.Show();
                return null;
            }
            return newbitmap;
        }
 // sets up dpi property
 private void SetDpi()
 {
     if (DefaultResolution.IsChecked != null)
     {
         if (!((bool) DefaultResolution.IsChecked))
         {
             try
             {
                 _settings.DPI = int.Parse(CustomResolutionTB.Text);
             }
             catch (Exception)
             {
                 _settings.DPI = 96;
                 const string alertText = "Custom DPI was not set correctly, DPI was set to default value (96)";
                 var alertDialog = new AlertDialog(alertText);
                 alertDialog.Show();
             }
         }
         else
         {
             _settings.DPI = 96;
         }
     }
 }
 private void On8ColorBoxFocusLost(object sender, RoutedEventArgs args)
 {
     try
     {
         _8ColorRect.Fill = new SolidColorBrush(
         Color.FromRgb(
         Convert.ToByte(Convert.ToInt32(_8Color.Text.Substring(0, 2), 16)),
         Convert.ToByte(Convert.ToInt32(_8Color.Text.Substring(2, 2), 16)),
         Convert.ToByte(Convert.ToInt32(_8Color.Text.Substring(4, 2), 16))));
     }
     catch (Exception)
     {
         _8Color.Text = _settings.ColorList[7];
         _8ColorRect.Fill = new SolidColorBrush(
             Color.FromRgb(
             Convert.ToByte(Convert.ToInt32(_settings.ColorList[7].Substring(0, 2), 16)),
             Convert.ToByte(Convert.ToInt32(_settings.ColorList[7].Substring(2, 2), 16)),
             Convert.ToByte(Convert.ToInt32(_settings.ColorList[7].Substring(4, 2), 16))));
         var alertDlg =
             new AlertDialog(
                 "Неверный формат кода цвета.");
         alertDlg.Show();
     }
 }