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
上。
请告诉我我做错了什么。