如何将 bitmapDescriptor 转换为位图?
How to convert bitmapDescriptor to bitmap?
我要实现的功能是:如果标记最接近用户选择的区域,则用特定图标放大标记。我将所有标记存储在一个集合 collectionOfMarkers() 和 findClosest() 方法中 returns 最接近用户区域的标记。
// Get closes marker
closestMarker= getClosestItem(collectionOfMarkers(),latLng);
mClusterRenderer.getMarker(closestMarker).setIcon(closestMarker.getIcon());
要调整那个标记的大小,我需要传递具有指定宽度和高度参数的新位图,但是它也需要位图源,而我只有 bitmapDescriptor 来自 closestMarker.getIcon()。有没有办法将 BitmapDescriptor 转换为位图?我没有图标名称或资源路径,因为标记可以代表多个图标,因此必须从标记本身中提取它。
public Bitmap resizeMapIcons(String iconName,int width, int height){
Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
return resizedBitmap;
}
像
一样使用它
googleMap.addMarker(new MarkerOptions()
.title("New Marker")
.snippet("Check out this place.")
.position(chelsea).icon(BitmapDescriptorFactory.fromBitmap(resizeMapIcons("image_name",100,100))));
我要实现的功能是:如果标记最接近用户选择的区域,则用特定图标放大标记。我将所有标记存储在一个集合 collectionOfMarkers() 和 findClosest() 方法中 returns 最接近用户区域的标记。
// Get closes marker
closestMarker= getClosestItem(collectionOfMarkers(),latLng);
mClusterRenderer.getMarker(closestMarker).setIcon(closestMarker.getIcon());
要调整那个标记的大小,我需要传递具有指定宽度和高度参数的新位图,但是它也需要位图源,而我只有 bitmapDescriptor 来自 closestMarker.getIcon()。有没有办法将 BitmapDescriptor 转换为位图?我没有图标名称或资源路径,因为标记可以代表多个图标,因此必须从标记本身中提取它。
public Bitmap resizeMapIcons(String iconName,int width, int height){
Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
return resizedBitmap;
}
像
一样使用它googleMap.addMarker(new MarkerOptions()
.title("New Marker")
.snippet("Check out this place.")
.position(chelsea).icon(BitmapDescriptorFactory.fromBitmap(resizeMapIcons("image_name",100,100))));