Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

javascript - Drawing GOOD LOOKING (like in Flash) lines on canvas (HTML5) - possible?

Is there any way to draw a line using javascript and the canvas with "better" antialiasing, like Flash does?

I know the Math.floor(coord)+0.5 trick to get an exactly 1 pixel line when you need it, but that's not what I mean. The following blue lines drawed using canvas look _ugly in all browsers supporting html5 and cavas, so they are probably using the same bad antialiasing algorithm (probably coded for speed, not for the best visual impression). It's the same no matter what the line width is (actually the thicker, the uglier):

1px blue lines screenshot crop:

alt text

and 3px:

alt text

As you can see, this is not the most beautiful way to draw good antialiased lines, and only the lower line looks good. The client is demanding that the graph manipulation app I work on must "look good" and is very demanding from the aesthetics pov and I will probably ditch the HTML5/Canvas solution and go the Flash way if I can't solve this problem. Or maybe I could code a good antialiased lines drawing algorith in javascript (can anyone give me some resources for that?) Sorry for not adding a picture with lines drawn in Flash, but the point is that they just look good, the antialiasing is done right.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Instead of using the 2D drawing API, you can use the SVG vector elements. You would have to implement your own api to do it, but that way you will get beautiful lines, like those in flash. The SVG-edit is an example of what you can do with SVN in browser.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...