Reputation: 933
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;
}
here is my code for draw my Location on Google map :
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);
//
}
}
Currently I am to displaying an Image on GoogleMaps
instead of marker but its displaying a Rectangular image. I want display it in circular shapre, I have written a method for displaying circular image, but I am not able to call this on GoogleMaps
for displaying image as circular shape in android.
Please tell me where am doing wrong .
Upvotes: 4
Views: 1763
Reputation: 264
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
BitmapDescriptor icon = BitmapDescriptorFactory
.fromBitmap(getCircleBitmap(bitmap));
Replace this Code and Enjoy!!!!
Upvotes: 4