Issues when using FloodFill and DrawableFillColor

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
jbmn14
Posts: 2
Joined: 2014-01-09T21:23:56-07:00
Authentication code: 6789

Issues when using FloodFill and DrawableFillColor

Post 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!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Issues when using FloodFill and DrawableFillColor

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
jbmn14
Posts: 2
Joined: 2014-01-09T21:23:56-07:00
Authentication code: 6789

Re: Issues when using FloodFill and DrawableFillColor

Post by jbmn14 »

That was it! Thanks for the quick workaround.
Post Reply