Beispiel #1
0
        private void AnalyzePlaceButton_Click(object sender, EventArgs e)
        {
            if (!coordinatesAnalyze.IsEmpty)
            {
                var pointDictionary = AreaColors(PointSide);
                using (StreamWriter writer = new StreamWriter($@"{ProjectDir}\pointColors.txt"))
                {
                    foreach (KeyValuePair <string, ColorInfo> keyValue in pointDictionary.OrderByDescending(elem => elem.Value.ColorCount))
                    {
                        writer.WriteLine($"{keyValue.Key} : {keyValue.Value.ColorCount}");
                    }
                }
                var pointAnalyze       = ColorsAnalyze(pointDictionary);
                var fragmentDictionary = AreaColors(RectSide);
                var fragmentAnalyze    = ColorsAnalyze(fragmentDictionary);
                var analyze            = new StringBuilder();

                if (detectSizeRadio.Checked)
                {
                    ImageColors(fragmentAnalyze);
                    var imageObjectsParameters         = FragmentObjectsSizeAnalyze(fragmentAnalyze);
                    var imageObjectsParametersPresence = imageObjectsParameters.Where(param => param.Value.Count > 0);
                    if (imageObjectsParametersPresence.Any())
                    {
                        foreach (var elem in imageObjectsParametersPresence)
                        {
                            var objectName = elem.Key;
                            analyze.AppendLine(DetectObjectName(objectName));
                            foreach (var objectParameters in elem.Value)
                            {
                                if (objectParameters.Area > 1)
                                {
                                    analyze.AppendLine($"Длина = {objectParameters.ArcLength}, площадь: {objectParameters.Area}");
                                }
                            }
                        }
                    }
                }
                var criteriaFragmentAnalyze = CriteriaObject.GetInstance().CalculateAnalyze(fragmentAnalyze);
                var criteriaPointAnalyze    = CriteriaObject.GetInstance().CalculateAnalyze(pointAnalyze, true);
                analyze.AppendLine(criteriaFragmentAnalyze);
                analyze.AppendLine(criteriaPointAnalyze);
                AnalyzeForm analyzeForm = new AnalyzeForm();
                analyzeForm.SetPointGridView(pointAnalyze);
                analyzeForm.SetFragmentGridView(fragmentAnalyze);
                analyzeForm.AddAnalyze(analyze.ToString());
                analyzeForm.Show();
            }
            else
            {
                MessageBox.Show("Выберите участок карты!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void Analyze()
        {
            var imageBitmap     = new Bitmap(ImageFile.GetInstance().Image);
            var colorDictionary = new Dictionary <string, ColorInfo>();
            var Width           = ImageFile.GetInstance().Image.Width;
            var Height          = ImageFile.GetInstance().Image.Height;

            if (!coordinatesAnalyze.IsEmpty)
            {
                var xstart = coordinatesAnalyze.X - RectSide / 2;
                var ystart = coordinatesAnalyze.Y - RectSide / 2;
                var xend   = coordinatesAnalyze.X + RectSide / 2;
                var yend   = coordinatesAnalyze.Y + RectSide / 2;
                var xmin   = xstart > 0 ? xstart : 0;
                var ymin   = ystart > 0 ? ystart : 0;
                var xmax   = xend < Width ? xend : Width;
                var ymax   = yend < Height ? yend : Height;


                for (int i = xmin; i < xmax; i++)
                {
                    for (int j = ymin; j < ymax; j++)
                    {
                        if (!(i == 0 || j == 0 || i == Width - 1 || j == Height - 1))
                        {
                            var medium     = imageBitmap.GetPixel(i - 1, j - 1);
                            var colorValue = medium.ToArgb().ToString();
                            var near       = ColorHelper.GetNearestColorName(ColorHelper.GetSystemDrawingColorFromHexString("#" + medium.Name.Substring(2)));

                            if (!colorDictionary.ContainsKey(colorValue))
                            {
                                colorDictionary.Add(colorValue, new ColorInfo {
                                    Color = medium, ColorCount = 1, NearColor = near
                                });
                            }
                            else
                            {
                                colorDictionary[colorValue].ColorCount += 1;
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Вы не выбрали фрагмент!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            var allColors  = colorDictionary.OrderByDescending(elem => elem.Value.ColorCount).ToList();
            var mainColors = allColors.Take(20).ToList();



            using (StreamWriter writer = new StreamWriter($@"{ProjectDir}\imageinfo.txt"))
            {
                foreach (KeyValuePair <string, ColorInfo> keyValue in colorDictionary.OrderByDescending(elem => elem.Value.ColorCount))
                {
                    Color col  = Color.FromArgb(Convert.ToInt32(keyValue.Key));
                    var   near = ColorHelper.GetNearestColorName(ColorHelper.GetSystemDrawingColorFromHexString("#" + col.Name.Substring(2)));

                    writer.WriteLine($"{keyValue.Key} : {keyValue.Value.ColorCount} , near color = {keyValue.Value.NearColor}");
                    writer.WriteLine(near);
                }
            }

            MessageBox.Show("Анализ проведён!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            AnalyzeForm analyzeForm = new AnalyzeForm();

            //analyzeForm.SetDataGridView(mainColors);

            analyzeForm.Show();
        }