protected override void Draw()
        {
            if (!SelectedPatch.x0.HasValue || !SelectedPatch.y0.HasValue)
            {
                return;
            }

            Rectangle crop;
            var       mask = _map.GetMask(SelectedPatch.x0.Value, SelectedPatch.y0.Value, out crop, GetPatchScale());

            mask = mask.Canny(new Gray(149), new Gray(255)).Dilate(5);

            // draw the mask on the image
            DisplayedImage.ROI = crop;
            for (int i = 0; i < mask.Rows; i++)
            {
                for (int j = 0; j < mask.Cols; j++)
                {
                    if ((float)mask[i, j].Intensity > 0)
                    {
                        DisplayedImage.Data[crop.Top + i, crop.Left + j, 0] = 255;
                        DisplayedImage.Data[crop.Top + i, crop.Left + j, 1] = 255;
                        DisplayedImage.Data[crop.Top + i, crop.Left + j, 2] = 0;
                        //new Rgb(Color.Yellow);
                    }
                }
            }
            DisplayedImage.ROI = Rectangle.Empty;

            DisplayedImage.Draw(crop, new Rgb(Color.Wheat), 1);

            // draw markers
            DrawMarker(SelectedPatch.x0.Value, SelectedPatch.y0.Value, new Rgb(Color.DodgerBlue));
            DrawCenterMarker();
        }
Example #2
0
        protected override void Draw()
        {
            DrawCenterMarker();

            // This will draw the patch boundaries
            if (SelectedPatch.x0.HasValue && SelectedPatch.x1.HasValue && SelectedPatch.y0.HasValue && SelectedPatch.y1.HasValue)
            {
                var r = new Rectangle(SelectedPatch.x0.Value, SelectedPatch.y0.Value,
                                      SelectedPatch.x1.Value - SelectedPatch.x0.Value,
                                      SelectedPatch.y1.Value - SelectedPatch.y0.Value);
                var c = SelectedPatch.IsRejected ? new Rgb(Color.DarkOrange) : new Rgb(Color.YellowGreen);
                DisplayedImage.Draw(r, c, 20);
            }
        }
Example #3
0
        /// <summary>Adds the given file to the displayed list</summary>
        private void ShowPicture(DisplayedImage image)
        {
            PictureBox  ctr    = new PictureBox();
            MemoryImage memory = new MemoryImage(image.Filename);             // this is used for its SVG handling.  We don't really need the memory buffer overhead!

            ctr.Image        = memory.GetNetImage();
            ctr.Tag          = image;
            ctr.Size         = new Size(100, 100);
            ctr.SizeMode     = PictureBoxSizeMode.Zoom;
            ctr.Margin       = new Padding(10, 10, 10, 10);
            ctr.Padding      = new Padding(10, 10, 10, 10);
            ctr.Click       += Image_Click;
            ctr.DoubleClick += Image_DoubleClick;
            pnlImages.Controls.Add(ctr);
        }
Example #4
0
        private async void DoSearch()
        {
            SetInfo(null, false);
            ClearImages();
            string text = txtText.Text;

            if (text.Length < MINCHARS)
            {
                m_Message = Strings.Item("SAW_Edit_OS_TooShort").Replace("%0", MINCHARS.ToString());
                return;
            }

            m_Message = Strings.Item("SAW_Edit_OS_Contacting");
            pnlImages.Invalidate();

            try
            {
                // sample URL: https://www.opensymbols.org/api/v1/symbols/search?q=house
                string searchResult = await GetStringAsync(@"https://www.opensymbols.org/api/v1/symbols/search?q=" + Uri.EscapeUriString(text));

                pnlImages.Invalidate();

                var json = JArray.Parse(searchResult);
                if (json.Count == 0)
                {
                    m_Message = Strings.Item("SAW_Edit_OS_NoneFound");
                }
                else
                {
                    if (json.Count > MAXIMAGES)
                    {
                        SetInfo(Strings.Item("SAW_Edit_OS_TooMany").Replace("%0", json.Count.ToString()).Replace("%1", MAXIMAGES.ToString()), true);
                    }
                    int failures = 0;
                    foreach (JObject imageJson in json.Take(MAXIMAGES))
                    {
                        try
                        {
                            DisplayedImage image = await GetImage(imageJson);

                            if (image != null)
                            {
                                if (m_Message != null)                                 // remove message, if any, once first image is displayed
                                {
                                    m_Message = null;
                                    pnlImages.Invalidate();
                                }
                                ShowPicture(image);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.LogSubError("Image " + (imageJson["symbol_key"]?.ToString() ?? "?") + " failed: " + ex.Message);
                            failures += 1;
                        }
                    }
                    if (failures > 0)
                    {
                        SetInfo(Strings.Item("SAW_Edit_OS_SomeFailed").Replace("%0", failures.ToString()), true);
                    }
                }
            }
            catch (Exception ex)
            {
                m_Message = Strings.Item("SAW_Edit_OS_Failed") + ex.Message;
                Utilities.LogSubError(ex);
            }
            pnlImages.Invalidate();
        }