[英]Rounding a bitmap image as a google maps marker icon
我有一个地图活动 ,该活动从解析服务器中检索图像和位置并将它们显示为地图上的标记,我想知道是否可以使这些标记变圆而不是矩形。
这是我的代码:
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));
}});}}}});}
那么,如何使这些标记变圆而不是矩形呢?
好吧,我找到了解决方案,这就是如果有人感兴趣
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;
}
然后像这样简单地提取缩略图
Bitmap thumbnail = ThumbnailUtils.extractThumbnail(getCroppedBitmap(bitmap),200,200);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.