目标是把我在画布上画的一幅画保存到firestore中。然后,我要导入保存的最新图形。我首先要做的是每次画东西时都保存位图。该位图随后保存在SharedReferences中,然后以json配置发送到firestore。那是有效的,问题是我找不到一个方法来使用它 drawBitmap
保存在画布中。
这就是 onDraw
中的方法 CanvasView
类,其中我将位图存储在SharedReferences中:
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Draw the bitmap that stores the path the user has drawn.
// Initially the user has not drawn anything
// so we see only the colored bitmap.
canvas.drawBitmap(mExtraBitmap, 0, 0, null);
//save last drawing
Gson gson = new Gson();
String canvas_json = gson.toJson(mExtraBitmap);
SharedPreferences.Editor preferencesEditor = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();
preferencesEditor.putString(CANVAS_BITMAP, canvas_json);
preferencesEditor.apply();
}
这是代码的一部分,我将位图存储在 MainActivity
班级:
Gson gson = new Gson();
String json = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()).getString("canvas", "json");
Map<String, Object> canvasView = new HashMap<>();
canvasView.put("canvas", json);
db.collection("paint")
.document("canvas")
.set(canvasView)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast savedToast = Toast.makeText(MainActivity.this, "Saved to the Cloud", Toast.LENGTH_LONG);
savedToast.show();
}
});
为了得到存储的位图,我将json文件转换成位图,但是我不知道在画布上需要在哪里使用它来再次绘制。
暂无答案!
目前还没有任何答案,快来回答吧!