2013-04-22 54 views
4

在我的Android應用程序中,我將從服務器中檢索一些座標將返回的數據。然後我使用這些座標來創建線條並在視圖中繪製它們。Android中的線路交叉點渲染

我想要一個以不同方式呈現的線條。例如:行渲染

enter image description here

線在頂部是原線,我希望它呈現爲在下面的形狀。

並且有一些線彼此相交。然後交集可能呈現如下:

enter image description here

路口呈現在左側的方式就是我想要的。

所以我不知道Android的圖形api是否支持這些操作?

回答

2

如果您使用Android Canvas來繪製路徑兩次,使用不同的筆觸大小和顏色。下面是一個創建Bitmap的示例,其圖像與您想要的類似:

// Creates a 256*256 px bitmap 
    Bitmap bitmap = Bitmap.createBitmap(256, 256, Config.ARGB_8888); 

    // creates a Canvas which draws on the Bitmap 
    Canvas c = new Canvas(bitmap); 

    // Creates a path (draw an X) 
    Path path = new Path(); 
    path.moveTo(64, 64); 
    path.lineTo(192, 192); 
    path.moveTo(64, 192); 
    path.lineTo(192, 64); 

    // the Paint to draw the path 
    Paint paint = new Paint(); 
    paint.setStyle(Style.STROKE); 

    // First pass : draws the "outer" border in red 
    paint.setColor(Color.argb(255, 255, 0, 0)); 
    paint.setStrokeWidth(40); 
    c.drawPath(path, paint); 

    // Second pass : draws the inner border in pink 
    paint.setColor(Color.argb(255, 255, 192, 192)); 
    paint.setStrokeWidth(30); 
    c.drawPath(path, paint); 

    // Use the bitmap in the layout 
    ((ImageView) findViewById(R.id.image1)).setImageBitmap(bitmap);