我是靠谱客的博主 踏实手套,这篇文章主要介绍安卓百度地图画线问题出现断裂出现的原因代码如下,现在分享给大家,希望可以做个参考。

  • 出现的原因

百度地图要求纹理图片宽高须是2的整数幂,如16*64。百度地图画线链接

我们自己系统的图片虽然是大小是2的倍数,但是安卓读取图片后把大小给改变了,导致长宽不是2的倍数,因此需要重新定义图片大小。

  • 代码如下

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private void showXunchaLine(List<LatLng> points) { try { Bitmap bitmap = BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.wenli_jiantou2); Bitmap bitmap_ = resizeImage(bitmap, 16, 64); BitmapDescriptor mRedTexture = BitmapDescriptorFactory.fromBitmap(bitmap_); List<BitmapDescriptor> textureList = new ArrayList<BitmapDescriptor>(); textureList.add(mRedTexture); //添加纹理索引 List<Integer> indexList = new ArrayList<>(); for (int i = 0; i < textureList.size(); i++) { indexList.add(i); } //设置折线的属性 OverlayOptions mOverlayOptions = new PolylineOptions() .width(15) .color(Color.parseColor("#5c96fa")) .points(points) .dottedLine(true) .customTextureList(textureList) .textureIndex(indexList); //在地图上绘制折线 //mPloyline 折线对象 mBaiduMap.addOverlay(mOverlayOptions); } catch (Exception e) { e.printStackTrace(); } } public static Bitmap resizeImage(Bitmap bm, int newWidth, int newHeight) { Bitmap newbm = null; if (bm != null) { // 获得图片的宽高 int width = bm.getWidth(); int height = bm.getHeight(); // 计算缩放比例 float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; // 取得想要缩放的matrix参数 Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); // 得到新的图片 newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); } return newbm; }

最后

以上就是踏实手套最近收集整理的关于安卓百度地图画线问题出现断裂出现的原因代码如下的全部内容,更多相关安卓百度地图画线问题出现断裂出现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部