Canvas translate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Canvas translate method.

This code example shows how to use the following methods:drawPath, restore, save, scale, translate
		super.onDraw(canvas);
 
		if (path != null) {
			int w = getWidth()/2;
			int h = getHeight()/2;
			canvas.save();
			canvas.scale(w,h);
			if (!leftArrow) {
				canvas.translate(1, 0);
			} 
			Paint p = new Paint();
			p.setAntiAlias(false);
			p.setARGB(175, 216, 216, 216);
			p.setStyle(Paint.Style.FILL);
			canvas.drawPath(path, p);
			p.setARGB(75, 0, 0, 0);
			p.setStrokeWidth(0.1f);
			p.setStrokeJoin(Join.ROUND);
			p.setStrokeCap(Cap.ROUND);
			p.setAntiAlias(true);

9
CodeRank
This code example shows how to use the following methods:drawRGB, drawRect, restore, rotate, save
            mPaint.setAntiAlias(true);
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            canvas.save();
            canvas.translate(dipToPx(getContext(), 400), dipToPx(getContext(), 200));
            canvas.rotate(45.0f);
            canvas.drawRGB(255, 255, 255);
            mPaint.setColor(0xffff0000);
            canvas.drawRect(-80.0f, -80.0f, 80.0f, 80.0f, mPaint);
            canvas.drawRect(0.0f, 0.0f, 220.0f, 220.0f, mPaint);            
            canvas.restore();
        } 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:drawBitmap, translate
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
             
            Log.d("OpenGLRenderer", "================= Draw");
 
            canvas.translate(120.0f, 50.0f);
            canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
 
            canvas.translate(0.0f, mBitmap1.getHeight());
            canvas.translate(0.0f, 25.0f);
            canvas.drawBitmap(mBitmap2, 0.0f, 0.0f, null);
             
            canvas.translate(0.0f, mBitmap2.getHeight());
            canvas.translate(0.0f, 25.0f);
            canvas.drawBitmap(mBitmap3, 0.0f, 0.0f, null);
        } 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:drawRect, restore, save, translate
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            //canvas.drawRGB(255, 255, 255); 
 
            canvas.translate(100.0f, 100.0f);
             
            // SRC modes 
            canvas.save();
 
            drawRects(canvas, Mode.SRC_OVER);
            canvas.translate(0.0f, 100.0f);
 
            drawRects(canvas, Mode.SRC_IN);
            canvas.translate(0.0f, 100.0f);            
 
            drawRects(canvas, Mode.SRC_OUT);
            canvas.translate(0.0f, 100.0f);
 
            drawRects(canvas, Mode.SRC_ATOP);

9
CodeRank
This code example shows how to use the following methods:drawCircle, drawText, restore, save, translate
This code example shows how to use the following methods:drawBitmap, restore, save, scale, translate
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            canvas.save();
            canvas.scale(0.3f, 0.3f);
            canvas.drawBitmap(mBitmap1, 0, 0, mBitmapPaint);
            canvas.restore();
 
            canvas.save();
            canvas.translate(mBitmap1.getWidth() * 0.3f + 96.0f, 0.0f);
            canvas.scale(0.3f, 0.3f);
            canvas.drawBitmap(mBitmap2, 0, 0, mBitmapPaint);
            canvas.restore();
        } 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:drawRGB, getMatrix, restore, save, translate
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            Log.d("Matrix", "m1=" + canvas.getMatrix());
 
            canvas.save();
            canvas.translate(10.0f, 10.0f);
            Log.d("Matrix", "m2=" + canvas.getMatrix());
            canvas.translate(20.0f, 20.0f);
            Log.d("Matrix", "m3=" + canvas.getMatrix());
            canvas.restore();
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:concat, drawARGB, drawBitmap, restore, save
 
        @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);

8
CodeRank
This code example shows how to use the following methods:getSaveCount, restoreToCount, rotate, scale, translate
        int right = getPaddingRight();
        int bottom = getPaddingBottom();
        int width = getWidth() - left - right;
        int height = getHeight() - top - bottom;
 
        int saveCount = canvas.getSaveCount();
 
        // Scale down the image first if required. 
        if ((getScaleType() == ImageView.ScaleType.FIT_CENTER) &&
                ((width < w) || (height < h))) {
            float ratio = Math.min((float) width / w, (float) height / h);
            canvas.scale(ratio, ratio, width / 2.0f, height / 2.0f);
        } 
        canvas.translate(left + width / 2, top + height / 2);
        canvas.rotate(-mCurrentDegree);
        canvas.translate(-w / 2, -h / 2);
        drawable.draw(canvas);
        canvas.restoreToCount(saveCount);
    } 
 

8
CodeRank
This code example shows how to use the following methods:clipRect, drawBitmap, drawColor, restore, save
                try { 
                    if (DEBUG) {
                        Log.d(TAG, "Redrawing: x=" + x + ", y=" + y);
                    } 
 
                    c.translate(x, y);
                    if (w < 0 || h < 0) {
                        c.save(Canvas.CLIP_SAVE_FLAG);
                        c.clipRect(0, 0, mBackground.getWidth(), mBackground.getHeight(),
                                Op.DIFFERENCE);
                        c.drawColor(0xff000000);
                        c.restore();
                    } 
                    if (mBackground != null) {
                        c.drawBitmap(mBackground, 0, 0, null);
                    } 
                } finally { 
                    sh.unlockCanvasAndPost(c);
                } 
            } 
8
CodeRank

Related Canvas translate Questions & Answers:

translate Method Overview
Preconcat the current matrix with the specified translation
See Code Examples for other Android Canvas Methods: