Page 1 of 1

Issues when using FloodFill and DrawableFillColor

Posted: 2014-01-09T21:31:25-07:00
by jbmn14
I am using Magick.NET to generate a weather advisory map with a text legend at the bottom of the image.

I use this code to fill counties that have a current advisory:

Code: Select all

            using (MagickImage image = new MagickImage(@"mnmap.png"))
            {               
                // Build Legend
                List<string> legendAlerts = new List<string>();

                foreach (AlertEntry alert in alerts)
                {
                    //MessageBox.Show(alert.Event);
                    char[] seps = { ',', ';' };
                    string[] counties = alert.Counties.Split(seps);

                    // Add for legend
                    if(!Util.IsDup(alert.Event,legendAlerts))
                        legendAlerts.Add(alert.Event);

                    foreach(string county in counties)
                    {
                        string coords = GetCountyCoords(county.Trim().ToLower());
                        if(coords != "")
                        {
                            string x = coords.Split(',')[0];
                            string y = coords.Split(',')[1];
                              
// Color Advisories via FloodFill
                            image.FloodFill(System.Drawing.ColorTranslator.FromHtml(GetColorCode(alert.Event)), int.Parse(x),int.Parse(y));

                        }
                    }
                }
I then take the list of advisories and generate a map legend below the image after I extend the existing image object:

Code: Select all

                // Legend
                image.Extent(300, 400, Gravity.North);
                int i = 325;

                foreach(string alert in legendAlerts)
                {
                    List<Drawable> drawables = new List<Drawable>();
                    drawables.Add(new DrawableFillColor(System.Drawing.ColorTranslator.FromHtml(GetColorCode(alert))));
                    drawables.Add(new DrawableFont("Segoe UI", FontStyleType.Any, FontWeight.Weight700, FontStretch.Normal));

                    drawables.Add(new DrawableText(30, i, alert));
                    image.Draw(drawables);
                    i = i + 12;
                }

                // Create final image file
                image.Transparent(Color.White);
                image.Write("newmap.png");
            }
The problem I am having is the DrawableFillColor that I am specifying for the text in the legend is not correct when displayed. It actually uses the same color that was the last color used in the image.FloodFill when coloring the map for advisories. If I comment out the FloodFill command, the DrawableFillColor is set correct and the text color is correct.

I'm not sure what would be causing the problem. Any help would be appreciated!

Re: Issues when using FloodFill and DrawableFillColor

Posted: 2014-01-10T16:57:47-07:00
by dlemstra
It seems that the FloodFill method changes the FillPattern of MagickImage which causes this side effect. You should set it to null for now. I will fix this in the next release.

Re: Issues when using FloodFill and DrawableFillColor

Posted: 2014-01-10T17:37:02-07:00
by jbmn14
That was it! Thanks for the quick workaround.