在我的 Android 应用程序中,我将从服务器检索数据,其中一些坐标将被返回。然后我使用这些坐标创建线条并在视图中绘制它们。
我想要一条以不同方式呈现的线条。例如:线条渲染
顶部的线是原始线,我希望它呈现为下面的形状。
并且有一些线彼此相交。那么交叉点可能会呈现如下:
左边的交集渲染方式是我想要的。
所以我想知道Android图形api是否支持这些操作?
如果您使用 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);