Android-将折线获取为图像 [英] Android - Get polyline as image
本文介绍了Android-将折线获取为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取已在Google地图上绘制为图形的折线? 仅折线,没有地图布局.
How do you get polyline that already plotted on Google Map as image? Only the polyline, without the map layout.
我已经在Google地图上绘制了折线,我想将折线作为图像获取.因此它只显示红线而没有任何地图
I have plotted the polyline on the Google Map and I want to get the polyline as an image. So it only show the red line without any map
https://i.stack.imgur.com/vUqS3.png
推荐答案
我设法通过将坐标更改为点来解决此问题
I manage to solve this by changing the coordinate to point
private Bitmap createPolylineBitmap() {
Bitmap bitmap = Bitmap.createBitmap(mapFragment.getView().getWidth(), mapFragment.getView().getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(ContextCompat.getColor(this, R.color.purple));
paint.setStrokeWidth(10);
paint.setDither(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setAntiAlias(true);
for (int i = 0; i < coordinates.size(); i++) {
LatLng latLng1 = new LatLng(coordinates.get(i).latitude, coordinates.get(i).longitude);
LatLng latLng2 = new LatLng(coordinates.get(i + 1).latitude, coordinatest.get(i + 1).longitude);
canvas.drawLine((LatLngToPoint(latLng1).x), ((LatLngToPoint(latLng1).y)), (LatLngToPoint(latLng2).x), (LatLngToPoint(latLng2).y), paint);
}
return bitmap;
}
private Point LatLngToPoint(LatLng coordinate) {
Projection projection = googleMap.getProjection();
return projection.toScreenLocation(coordinate);
}
这篇关于Android-将折线获取为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文