You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rasterizing artifacts when rendering line with DrawLines #15
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.IO;usingNewtonsoft.Json.Linq;usingSixLabors.Primitives;usingSixLabors.ImageSharp.PixelFormats;usingSixLabors.ImageSharp.Processing;usingSixLabors.ImageSharp;usingSixLabors.Shapes;namespaceImageCreator{classImageCreatorApp{privatestaticIEnumerable<IReadOnlyList<PointF>>EnumerateLines(JTokengeometry){// map the longitude (horizontal) to 0 - 360// map the latitude (vertical) to 0 - 180stringtype=geometry["type"].ToString();List<PointF>line=newList<PointF>();if(type.Equals("multipolygon",StringComparison.OrdinalIgnoreCase)){foreach(JArraypolygonGroupingeometry["coordinates"]){foreach(JArraypolygoninpolygonGroup){foreach(JTokencoordinpolygon){floatlon=coord[0].Value<float>()+180.0f;if(lon>180.0){lon=(360.0f-lon);}floatlat=coord[1].Value<float>()+90.0f;if(lat>90.0f){lat=(180.0f-lat);}line.Add(newPointF(lon,lat));}yieldreturnline;line.Clear();}}}elseif(type.Equals("polygon",StringComparison.OrdinalIgnoreCase)){foreach(JArraypolygoningeometry["coordinates"]){foreach(JTokencoordinpolygon){floatlon=coord[0].Value<float>()+180.0f;if(lon>180.0){lon=(360.0f-lon);}floatlat=coord[1].Value<float>()+90.0f;if(lat>90.0f){lat=(180.0f-lat);}line.Add(newPointF(lon,lat));}yieldreturnline;line.Clear();}}}publicstaticintMain(string[]args){if(args.Length==0){Console.WriteLine("Pass geo-json files as arguments");return-1;}// have to acquire the ranges first...List<JToken>fileTokens=newList<JToken>();floatminLat=float.MaxValue;floatminLon=float.MaxValue;floatmaxLat=float.MinValue;floatmaxLon=float.MinValue;foreach(stringfileinargs){JObjecttoken=JObject.Parse(File.ReadAllText(file));fileTokens.Add(token);varresults=token.Descendants().OfType<JProperty>().Where(t =>t.Name=="geometry").Select(t =>t.Value);foreach(JTokengeometryinresults){foreach(PointFcoordinEnumerateLines(geometry).SelectMany(l =>l)){minLon=Math.Min(minLon,coord.X);minLat=Math.Min(minLat,coord.Y);maxLon=Math.Max(maxLon,coord.X);maxLat=Math.Max(maxLat,coord.Y);}}}floatrangeLon=1.0f/MathF.Abs(maxLon-minLon);floatrangeLat=1.0f/MathF.Abs(maxLat-minLat);floatwidth=4096.0f;floatheight=2048.0f;floatmaxWidth=(width-1.0f);floatmaxHeight=(height-1.0f);SixLabors.ImageSharp.Image<Rgba32>img=newSixLabors.ImageSharp.Image<Rgba32>((int)width,(int)height);img.Mutate(m =>m.Fill(Rgba32.Black));GraphicsOptionsoptions=newGraphicsOptions{Antialias=false};foreach(JObjectfileTokeninfileTokens){varresults=fileToken.Descendants().OfType<JProperty>().Where(t =>t.Name=="geometry").Select(t =>t.Value);foreach(JTokengeometryinresults){foreach(List<PointF>lineinEnumerateLines(geometry)){for(inti=0;i<line.Count;i++){line[i]=newPointF(Math.Min(maxWidth,(int)Math.Round(width*(1.0f-(rangeLon*MathF.Abs(maxLon-line[i].X))))),Math.Min(maxHeight,(int)Math.Round(height*(1.0f-(rangeLat*MathF.Abs(maxLat-line[i].Y))))));}if(line.Count>3){img.Mutate(m =>m.DrawLines(options,Rgba32.White,1.0f,line.ToArray()));}}}}img.Save(File.OpenWrite(@"image.png"),newSixLabors.ImageSharp.Formats.Png.PngEncoder());return0;}}}
@jjxtra Thanks for providing so much detail, much appreciated!
That looks like an issue to me so will reopen. In the interim could you please check again with the nightly code from MyGet and see if the issue persists there.
Activity
zati- commentedon May 15, 2018
Same problem here, workaround is to disable antialiasing
antonfirsov commentedon May 15, 2018
Might be related to (or actually the same issue as) SixLabors/ImageSharp#572 and SixLabors/Shapes/#42.
@tocsoft is my supposition right?
tocsoft commentedon May 15, 2018
yeah, looks like its going to be the exact same root issues.
woutware commentedon May 22, 2018
This is indeed a duplicate of SixLabors/ImageSharp#572.
I've verified it now works ok after the fix, see attached image.
JimBobSquarePants commentedon May 23, 2018
Closing now as in nightlies
antonfirsov commentedon May 23, 2018
Shouldn't be fixed yet.
SL.ImageSharp.Drawingis still referencing shapes1.0.0-ci0018.We still need a PR updating shapes.
JimBobSquarePants commentedon May 23, 2018
I thought the PR was in no?
antonfirsov commentedon May 23, 2018
@JimBobSquarePants only in SL.Shapes: SixLabors/Shapes#43
We need to update the reference to have these issues closed.
antonfirsov commentedon May 26, 2018
Fixed with SixLabors/ImageSharp#596 in beta4.
jjxtra commentedon Aug 14, 2019
Any plans to put fix in a nuget package?
JimBobSquarePants commentedon Aug 14, 2019
@jjxtra It was back in May 2018.
https://www.nuget.org/packages/SixLabors.ImageSharp/1.0.0-beta0004
Are you still seeing issues with either beta6 or the latest nightly builds from MyGet?
jjxtra commentedon Aug 14, 2019
Yes with beta 6. Rendering us state lines onto an image, I am seeing horizontal gray lines if anti alias is on.
jjxtra commentedon Aug 14, 2019
Beta 6 / latest nuget:
Antialias On:

Antialias Off:

jjxtra commentedon Aug 14, 2019
Code is fairly straightforward, geo-json file...
jjxtra commentedon Aug 14, 2019
States Geo-Json File Download
JimBobSquarePants commentedon Aug 14, 2019
@jjxtra Thanks for providing so much detail, much appreciated!
That looks like an issue to me so will reopen. In the interim could you please check again with the nightly code from MyGet and see if the issue persists there.
JimBobSquarePants commentedon Aug 14, 2019
@jjxtra No need to do the additional testing for now. Cause is here. https://github.com/SixLabors/Shapes/issues/44
We can use your information to formulate a fix.
jjxtra commentedon Aug 14, 2019
Awesome, let me know if you need more info.
jjxtra commentedon Aug 21, 2019
Sorry, wrong dll. The latest master branch as of 2019-08-21 still has the anti-alias line issue.
antonfirsov commentedon Jan 17, 2020
Closing as Duplicate of #5.