私は、キャンバス上にあるものをビットマップに変換する方法をオンラインで検索してきました。描画キャッシュをビットマップに保存するなど、これを行うための複数の方法を試みましたが、最終的には背景のビットマップが一時的に点滅し、その後黒い画面に変わります。テスト画像は背景の上に表示されますが、次にの呼び出しからの背景によってオーバーレイされませんOnDraw
。
MainThreading{
...
if(notuptodate == true){
//call readyBackground to create the background bitmap
this.mainPanel.readyBackground(canvas);
//post the canvas
surfaceHolder.unlockCanvasAndPost(canvas);
//clean the Canvas
canvas = null;
//ready new Canvas
canvas = this.surfaceHolder.lockCanvas();//lock the canvas to enable editing
}//if not true
if (MainThreading.notuptodate == false){
mainPanel.onDraw(canvas);
}//if false
...
}//mainthreading
//this method is run first to create the Bitmap that on draw will use
public void readyBackGround(Canvas canvas){
if (MainThreading.notuptodate){
//method used to draw multiple Bitmaps onto the canvas
renderBackground(canvas);
//private Bitmap, this is the supposed proper size of the bitmap
backgroundBitmap=Bitmap.createBitmap(240, 320, Config.ARGB_8888);
//set the canvas to turn whats on its self onto the bitmap.
canvas.setBitmap(backgroundBitmap);
//set boolean flag to false so renderBackground won't be called
//untill it needs to be updated again
MainThreading.notUpToDate = false;
}
//this method is called when notUpToDate = true
@Override
protected void onDraw(Canvas canvas){
if (this.threado.getBackground() != null){
canvas.drawBitmap(backgroundBitmap, 0, 0, null);
}
//this if statement is never activated
if (this.threado.getBackground() == null){
Log.d("background nonexistant", "Importante!");
}
//draw test object onto background
test.DrawObject(canvas);
//when MainThreading.notUpToDate = true isn't commented out, the
//screen consistantly shows the background, but the test object isn't
//drawn
//MainThreading.notUpToDate = true;
}