如何在Android的Google地图上显示圆形图片中的图片

4
private Bitmap getCircleBitmap(Bitmap bitmap) {
     final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
      bitmap.getHeight(), Bitmap.Config.ARGB_8888);
     final 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);

     paint.setAntiAlias(true);
     canvas.drawARGB(0, 0, 0, 0);
     paint.setColor(color);
     canvas.drawOval(rectF, paint);

     paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
     canvas.drawBitmap(bitmap, rect, rect, paint);

     bitmap.recycle();

     return output;
    }

以下是我用来在Google地图上标注我的位置的代码:

public void drawMyLocation() {
        GPSTracker gps = new GPSTracker(getActivity());
        String imagePath = Environment.getExternalStorageDirectory().toString()
                + "/LociiImages/" + member_id + ".jpg";
        BitmapDescriptor icon = BitmapDescriptorFactory.fromPath(imagePath);

    //  getCircleBitmap(icon);

        if (gps.canGetLocation()) {
            double mylat = gps.getLatitude();
            double mylong = gps.getLongitude();
            LatLng myPoint = new LatLng(mylat, mylong);
            MarkerOptions marker = new MarkerOptions();
            marker.position(myPoint);
            marker.title("You");
            marker.snippet("You are here.");
            marker.icon(icon);
            map.addMarker(marker);


            // // Move the camera instantly to hamburg with a zoom of 15.
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(myPoint, 15));
            //
            // // Zoom in, animating the camera.
            map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
            //

        }
    }

目前我正在在GoogleMaps上显示一张图片,而不是标记,但它显示的是一个矩形图片。我想要以圆形形状显示它,我已经编写了一个显示圆形图片的方法,但我无法在安卓上调用它来显示圆形形状的图片在GoogleMaps上。

请告诉我我做错了什么。


1
BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(getCircleBitmap(yourBitmap))。(注:该句为Java代码,无法进行翻译,只能提供中文版的代码) - Murtaza Khursheed Hussain
你的位图将会是什么?@Murtaza Hussain - Edge
1个回答

4
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);



    BitmapDescriptor icon = BitmapDescriptorFactory
            .fromBitmap(getCircleBitmap(bitmap));

替换这段代码,享受它的便利!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接