Android中的线交叉渲染

时间:2013-04-22 00:45:33

标签: android graphics

在我的Android应用程序中,我将从服务器检索数据,其中一些坐标将被返回。然后我使用这些坐标创建线条并在视图中绘制它们。

我想要一个以不同方式呈现的线条。例如:线条渲染

enter image description here

顶部的线是原始线,我希望它呈现为下面的形状。

并且有一些线相互交叉。然后可以如下呈现交集:

enter image description here

左边交叉渲染的方式就是我想要的。

所以我想知道Android图形API是否支持这些操作?

1 个答案:

答案 0 :(得分:2)

如果您使用Android Canvas执行此操作两次绘制路径,使用不同的笔触大小和颜色。这是一个创建具有类似于您想要的图像的位图的示例:

    // 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);