问题
I am drawing a line to a Graphics
object in Windows CE using C#.NET 3.5.
The code I am using looks like this:
e.Graphics.DrawLine(new Pen(Color.FromArgb(11, 118, 200), 2), x1, y1, x2, y2);
This works however looks terrible due to jaggies etc. Is there anyway I can draw anti aliased lines?
From what I can tell the Graphics
object doesn't support this natively but is there anyway to "cheat" this effect using some trickery?
回答1:
A fast trick if you're drawing on a solid color background, you can draw a line with a thicker pen and a color in between the background color and the line color prior to the actual line, for instance, when drawing on a black background:
e.Graphics.DrawLine(new Pen(Color.FromArgb(5, 59, 100), 3), x1, y1, x2, y2);
e.Graphics.DrawLine(new Pen(Color.FromArgb(11, 118, 200), 2), x1, y1, x2, y2);
This adds a "glow" to the line (even on perfect horizontal / vertical lines though).
回答2:
I feel your pain. I was doing something similar a few years ago for .NETCF and I was going down all sorts of funny paths. Ended up more work than it was worth. Have a look at this awfulness:
http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm
http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/b34f56c4-585b-4ff5-ac7d-b6e2ae516ccf/
Also, this might serve some answers but could be a useful replacement for the WM GDI system.
http://drawingcf.codeplex.com/
This question lead me to the http://www.amanithvg.com/project.html which offers an OpenGL like framework with Windows CE libraries. Might be mega-overkill though just for a few lines.
Finally, you could always just use a bitmap, but you might have problems with transparency later on.
回答3:
Found this XrossGDI+ complete native C#:
http://www.isquaredsoftware.com/XrossOneGDIPlus.php
来源:https://stackoverflow.com/questions/4735238/anti-aliasing-drawline-on-ce