Canvas save - 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 save 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: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:clipRect, getMatrix, restore, save, setMatrix
        if (Build.VERSION.SDK_INT >= 16) {
            super.onDraw(canvas);
            return; 
        } 
 
        canvas.save();
 
        if(mTitleBar != null) {
            final int sy = getScrollY();
            final int sx = getScrollX();
            mClipBounds.top = sy;
            mClipBounds.left = sx;
            mClipBounds.right = mClipBounds.left + getWidth();
            mClipBounds.bottom = mClipBounds.top + getHeight();
            canvas.clipRect(mClipBounds);
            mMatrix.set(canvas.getMatrix());
            int titleBarOffs = getVisibleTitleHeightCompat();
            if(titleBarOffs < 0) titleBarOffs = 0;
            mMatrix.postTranslate(0, titleBarOffs);
            canvas.setMatrix(mMatrix);

8
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:drawColor, restore, save, setBitmap
    private Bitmap createPressImage(ImageView v, Canvas canvas) {
        final Drawable d = v.getDrawable();
        final Bitmap b = Bitmap.createBitmap(
                d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
 
        canvas.setBitmap(b);
        canvas.save();
            d.draw(canvas);
        canvas.restore();
        canvas.drawColor(mHighlightColor, PorterDuff.Mode.SRC_IN);
        canvas.setBitmap(null);
 
        return b;
    } 
} 
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
This code example shows how to use the following methods:restore, restoreToCount, save, scale, translate
8
CodeRank

Related Canvas save Questions & Answers:

save Method Overview
Saves the current matrix and clip onto a private stack.
See Code Examples for other Android Canvas Methods: