如何在Android上的谷歌地图上的圆形图像上显示图像

时间:2015-01-19 10:16:13

标签: android

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而不是标记上显示图像,但它显示的是矩形图像。我希望以圆形shapre显示它,我已经编写了一个显示圆形图像的方法,但是我无法在GoogleMaps上调用它来在android中将图像显示为圆形。

请告诉我哪里出错了。

0 个答案:

没有答案