简体   繁体   English

Chrome使用哪种抗锯齿的线条绘制算法?

[英]What antialiased line drawing algorithm is used by Chrome?

I'm importing a lot of raw drawing data (strokes) and converting it to images. 我正在导入大量原始图形数据(笔触)并将其转换为图像。 I used the basic HTML5 Canvas until now, which worked fine. 到目前为止,我一直使用基本的HTML5 Canvas,效果很好。 But I wanted to implement the line drawing algorithm myself, as it saves a lot of hassle. 但是我想自己实现线条绘制算法,因为它节省了很多麻烦。

So I implemented Xiaolin Wu's line algorithm , but when i compare it to my previous results with Canvas it didn't really look good: 因此,我实现了Xiaolin Wu的line算法 ,但是当我将其与Canvas之前的结果进行比较时,效果并不理想:

Left 5 columns: Xiaolin Wu's line algorithm, Right 5 columns: HTML5 Canvas (latest version Chrome) algorithm 左5列:吴晓琳的行算法,右5列:HTML5 Canvas(最新版Chrome)算法

So what algorithm are they using? 那么他们使用什么算法? Is source code available? 是否提供源代码? All I need is the algorithm of drawing single lines. 我所需要的只是绘制单条线的算法。

Google Chrome is powered by Chromium which is Open Source. Google Chrome由Chromium(开源)提供支持。

The main Chromium project is located at https://www.chromium.org/ . Chromium的主要项目位于https://www.chromium.org/

The source code is available at https://chromium.googlesource.com/ . 可从https://chromium.googlesource.com/获得源代码。

Next step is to browse a bit. 下一步是浏览一下。 They are using the library Skia to draw which is also Open Source. 他们正在使用Skia库进行绘制,这也是开源的。 You can use it in your project and you should be good. 您可以在项目中使用它,您应该会很好。

Demo : 演示

void draw(SkCanvas* canvas) {
    canvas->drawColor(SK_ColorWHITE);

    SkPaint paint;
    paint.setStyle(SkPaint::kStroke_Style);
    paint.setStrokeWidth(8);
    paint.setColor(0xff1f78b4);
    paint.setAntiAlias(true);
    paint.setStrokeCap(SkPaint::kRound_Cap);

    SkPath path;
    path.moveTo(10, 10);
    path.quadTo(256, 64, 128, 128);
    path.quadTo(10, 192, 250, 250);
    canvas->drawPath(path, paint);
}

演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM