简体   繁体   English

在android上的geopoints之间绘制平滑线

[英]Draw smooth line between geopoints on android

I've drawed line between geopoints. 我在地理位置之间画了一条线。 its successfully drawed. 它成功地画了。 when we see the map, the drawline look like pixelated when adjecent of next drawling. 当我们看到地图时,当下一次拉伸时,画线看起来像是像素化的。 how to merge the line? 如何合并线?

在此输入图像描述

My code is here, 我的代码在这里,

@Override
public void draw(Canvas canvas, MapView mapview, boolean shadow) {
    super.draw(canvas, mapview, shadow);
    if(! routeIsActive) return;

    mapview.getProjection().toPixels(locpoint, pp);       // Converts GeoPoint to screen pixels

    int xoff = 0;
    int yoff = 0;
    int oldx = pp.x;
    int oldy = pp.y;
    int newx = oldx + xoff;
    int newy = oldy + yoff;

    paint.setAntiAlias(true);
    paint.setDither(true);
            paint.setStrokeWidth(7);
    for(int i=0; i<numberRoutePoints-1; i++)
    {
        switch(routeMode.get(i))
        {
        case 0:
            paint.setColor(Color.parseColor("#666666"));
            break;
        case 1:
            paint.setColor(Color.parseColor("#0EA7D6"));
            break;
        case 2:
            paint.setColor(Color.parseColor("#654321"));
            break;
        case 3:
            paint.setColor(Color.parseColor("#123456"));
            break;
        }   

        mapview.getProjection().toPixels(routePoints.get(i), pold);
        oldx = pold.x;
        oldy = pold.y;
        mapview.getProjection().toPixels(routePoints.get(i+1), pnew);
        newx = pnew.x;
        newy = pnew.y;

        canvas.drawLine(oldx, oldy, newx, newy, paint);
    }

}

你应该改变paint对象的样式,如下所示:

paint.setStrokeCap(Cap.ROUND);

如果你在每一行的开头和结尾绘制一个圆圈(圆的直径必须是线高),我认为它可以做到这一点,或者画布的drawRoundRect可以做得很好

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

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