I have a map activity that retrieves images and locations from a parse server and show them as a marker on the map, I was wondering if I can make these markers rounded instead of the rectangle shape.
Here is my code:
public void getimagesLocation(){
ParseQuery<ParseObject> query = ParseQuery.getQuery("Image");
ParseGeoPoint geoPointLocation = new ParseGeoPoint();
query.whereNear("location", geoPointLocation);
query.setLimit(100);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
Log.i("imageslocation", "no errors");}
if (objects.size() > 0) {
for (ParseObject object : objects) {
final ParseGeoPoint point = object.getParseGeoPoint("location");
ParseFile file = (ParseFile) object.get("image");
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null && data != null);
Bitmap bitmap = BitmapFactory.decodeByteArray(data,0,data.length);
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(bitmap,200,200);
Double lat = point.getLatitude();
Double log = point.getLongitude();
LatLng marker = new LatLng(lat, log);
mMap.addMarker(new MarkerOptions()
.title("Another Image")
.icon(BitmapDescriptorFactory.fromBitmap(thumbnail))
.position(marker));
}});}}}});}
So, how make these markers rounded instead of the rectangle shape?
alright i found a solution and here it is if someone is interested
public Bitmap getCroppedBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
bitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
then simply extracted the thumbnail using it like this
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(getCroppedBitmap(bitmap),200,200);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.