Code example for Canvas

Methods: clipRect, drawBitmap, getSaveCount, restore, restoreToCount, save, saveLayer

0
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            int count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "count=" + count);
            count = canvas.save();
            Log.d("OpenGLRenderer", "count after save=" + count);
            count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "getSaveCount after save=" + count);
            canvas.restore();
            count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "count after restore=" + count);
            canvas.save();
            Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount());
            canvas.save();
            Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount());
            canvas.save();
            Log.d("OpenGLRenderer", "count after save=" + canvas.getSaveCount());
            canvas.restoreToCount(count);
            count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "count after restoreToCount=" + count);
            count = canvas.saveLayer(0, 0, 10, 10, mBitmapPaint, Canvas.ALL_SAVE_FLAG);
            Log.d("OpenGLRenderer", "count after saveLayer=" + count);
            count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "getSaveCount after saveLayer=" + count);
            canvas.restore();
            count = canvas.getSaveCount();
            Log.d("OpenGLRenderer", "count after restore=" + count);
 
            canvas.save();
            canvas.clipRect(0.0f, 0.0f, 40.0f, 40.0f);
            canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
            canvas.drawBitmap(mBitmap1, -mBitmap1.getWidth(), 0.0f, mBitmapPaint);
            canvas.drawBitmap(mBitmap1, 50.0f, 0.0f, mBitmapPaint);
            canvas.restore();
        } 
    } 
}