【发布时间】:2020-01-22 18:01:43
【问题描述】:
我想将 android.graphics.Bitmap 保存在 Firebase 存储中!
我的 android.graphics.Bitmap 是我将用户选择的图像分配给我使用 XML 创建的空标记模板时得到的自定义标记
这是我的标记创建函数:
public Bitmap createCustomMarker(Context context) {
View marker = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);
CircleImageView markerImage = (CircleImageView) marker.findViewById(R.id.user_dp);
markerImage.setImageBitmap(photoDuMarkeur); //"photoDuMarkeur" is the image selected by User
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
marker.setLayoutParams(new ViewGroup.LayoutParams(52, ViewGroup.LayoutParams.WRAP_CONTENT));
marker.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
marker.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(marker.getMeasuredWidth(), marker.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
marker.draw(canvas);
return bitmap;
}
这是我的空标记模板:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/custom_marker_view"
android:layout_width="82dp"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/user_dp"
android:layout_width="45dp"
android:layout_height="58dp"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="6dp"
android:contentDescription="@null"
android:src="@drawable/ccc"
app:civ_border_color="#fff" />
<RelativeLayout
android:layout_width="71dp"
android:layout_height="76dp"
android:background="@drawable/markerfin"
android:backgroundTint="@color/whiteMarker">
</RelativeLayout>
</RelativeLayout>
当我测试时:
Log.d ( "test", "************************************ "+ createCustomMarker (Marker.this));
我收到这个输出:
D/test: ************************************ android.graphics.Bitmap@78364bb
注意:函数或 XML 没有问题,我在 Map 甚至 ImageView 中都显示了标记,但我想保存这个标记“android.graphics.Bitmap@78364bb”在 Firebase 中!
【问题讨论】:
标签: firebase android-layout bitmap google-maps-markers firebase-storage