android 百度地图 marker设置忽明忽暗闪烁点

android 百度地图 marker设置忽明忽暗闪烁点说下思路

 百度地图设置marker的时候可以这是icon和icons

思路就是设置几个不同透明度的相同的图片的bitmap作为icons

话不多说 直接上码


1。这是核心代码

  

//闪烁点
bb是获取的image的bitmap
bitmaps = makeRoundCorner(bb);
Bitmap sbitmap = zoomImage(bitmaps, 90, 90);
BitmapDescriptor bitmap1 = BitmapDescriptorFactory.fromBitmap(sbitmap);
BitmapDescriptor bitmap2 = BitmapDescriptorFactory.fromBitmap(getAlplaBitmap(sbitmap,75));
BitmapDescriptor bitmap3 = BitmapDescriptorFactory.fromBitmap(getAlplaBitmap(sbitmap,50));
BitmapDescriptor bitmap4 = BitmapDescriptorFactory.fromBitmap(getAlplaBitmap(sbitmap,25));
BitmapDescriptor bitmap5 = BitmapDescriptorFactory.fromBitmap(getAlplaBitmap(sbitmap,0));

ArrayList<BitmapDescriptor> list = new ArrayList<>();
list.add(bitmap1);
list.add(bitmap2);
list.add(bitmap3);
list.add(bitmap4);
list.add(bitmap5);
OverlayOptions options = new MarkerOptions()
        .position(latLng)//设置marker的位置
        .icons(list)  //设置marker图标!!!!!这是重点
        .zIndex(5) //设置marker所在层级
        .title(i + "")
        .draggable(true);  //设置手势拖拽
//将marker添加到地图上
Marker m= (Marker) mBaiduMap.addOverlay(options);
markers.add(m);


2.这是对bitmap的处理的几个方法


/**
*从网络获取bitmap
**/
 @Nullable
 public static Bitmap GetLocalOrNetBitmap(String url) throws IOException {
     Bitmap bitmap = null;
     InputStream in = null;
     BufferedOutputStream out = null;
     try {
         in = new BufferedInputStream(new URL(url).openStream(), 10 * 10);
         final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
         out = new BufferedOutputStream(dataStream, 10 * 10);
         copy(in, out);
         out.flush();
         byte[] data = dataStream.toByteArray();
         bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
         data = null;
         return bitmap;
     } catch (IOException e) {
         e.printStackTrace();
         return null;
     } finally {

         assert in != null;
         in.close();
         assert out != null;
         out.close();

     }
 }

 /*
* bitmap设置任意透明度
* */
 public static Bitmap getAlplaBitmap(Bitmap sourceImg, int number) {
     int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
     sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg.getWidth(), sourceImg.getHeight());
     number = number * 255 / 100;
     for (int i = 0; i < argb.length; i++) {
         argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF);
     }
     sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg.getHeight(), Bitmap.Config.ARGB_8888);
     return getRoundedCornerBitmap(sourceImg);
 }

 /*
 * bitmap设置圆角
 * */
 public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
     Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
             bitmap.getHeight(), Bitmap.Config.ARGB_8888);
     Canvas canvas = new Canvas(output);
     final int color = Color.RED;

     final Paint paint = new Paint();

     final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

     final RectF rectF = new RectF(rect);

     final float roundPx = 200;

     paint.setAntiAlias(true);

     canvas.drawARGB(0, 0, 0, 0);

     paint.setColor(color);

     canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

     paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

     canvas.drawBitmap(bitmap, rect, rect, paint);

     return output;

 }