Code example for Canvas

Methods: concatdrawARGBdrawBitmaprestoresavetranslate

0
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            canvas.drawARGB(255, 255, 255, 255);
 
            final float centerX = getWidth() / 2.0f - mBitmap1.getWidth() / 2.0f;
            final float centerY = getHeight() / 2.0f - mBitmap1.getHeight() / 2.0f;
            final Camera camera = mCamera;
             
            final Matrix matrix = mMatrix;
 
            rotate(centerX, centerY, camera, matrix, 32.0f);
            drawBitmap(canvas, centerX, centerY, 0.0f, matrix);
 
            rotate(centerX, centerY, camera, matrix, 12.0f);
            drawBitmap(canvas, centerX, centerY, -mBitmap1.getWidth(), matrix);
             
            rotate(centerX, centerY, camera, matrix, 52.0f);
            drawBitmap(canvas, centerX, centerY, mBitmap1.getWidth(), matrix);
             
            rotate(centerX, centerY, camera, matrix, 122.0f);
            drawBitmap(canvas, centerX, centerY, mBitmap1.getWidth() * 2.0f, matrix);
             
        } 
 
        private void drawBitmap(Canvas canvas, float centerX, float centerY, float offset,
                Matrix matrix) {
            canvas.save();
            canvas.translate(offset, 0.0f);
            canvas.concat(matrix);
            canvas.drawBitmap(mBitmap1, centerX, centerY, null);
            canvas.restore();
        } 
 
        private void rotate(float centerX, float centerY, Camera camera,
                Matrix matrix, float angle) {
            camera.save();