Mokus
Mokus

Reputation: 10410

How can I store the background?

I have a linechart, what I would like to achieve not to redraw the grid each time. I tried the following, but the grid only visible in the first time, it seams that the saveLayer not working, or I just making it in the wrong way.

protected void onDraw(Canvas canvas) {
        if (mRedrawGrid) {
            drawGrid(canvas);
            mGridLayer = canvas.saveLayer(0, 0, getWidth(), getHeight(), mPaint, Canvas.MATRIX_SAVE_FLAG);
        } else
            canvas.restoreToCount(mGridLayer);
        drawLineChart(canvas);
    }

Upvotes: 0

Views: 60

Answers (1)

Bhavin Nattar
Bhavin Nattar

Reputation: 3215

May this help you:

Buddy take your Canvas on a LinearLayout and then save the whole LinearLayout's background into a bitmap like:

ll.buildDrawingCache();
Bitmap bt = ll.getDrawingCache();

Upvotes: 1

Related Questions