Canvas drawRect - 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 drawRect method.

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, drawRect
        if (mNeedRebuild) {
 
            if (mMapPin == null) {
                mMapPin = Bitmap.createBitmap(mBase.getWidth(), mBase.getHeight(), Bitmap.Config.ARGB_8888);
            } 
            Canvas c = new Canvas(mMapPin);
            c.drawRect(0, 0, mMapPin.getWidth(), mMapPin.getHeight(), sClearerPaint);
 
            // 1 - Draw the base 
            c.drawBitmap(mBase, 0, 0, null);
            // 2 - Draw the pin on top of it 
            mPaint.setColorFilter(new LightingColorFilter(Color.BLACK, mCurrentPinColor));
            c.drawBitmap(mPin, 0, 0, mPaint);
            // 3 - Draw the dot on top of everything 
            mPaint.setColorFilter(new LightingColorFilter(Color.BLACK, mCurrentDotColor));
            c.drawBitmap(mDot, 0, 0, mPaint);
 
            mNeedRebuild = false;
        } 
 
        canvas.drawBitmap(mMapPin, null, getBounds(), mMapPinPaint);
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:drawRGB, drawRect, restore, save, translate
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);
 
            canvas.save();
            canvas.translate(130.0f, 100.0f);
 
            mSweepGradient.setLocalMatrix(mMatrix3);
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(400.0f, 000.0f);
             
            mSweepGradient.setLocalMatrix(mMatrix);
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);            
 

9
CodeRank
This code example shows how to use the following methods:drawRect, getHeight, getWidth
        if (DEBUG) {
            Paint pt = new Paint();
            pt.setColor(0x80FFFF00);
            pt.setStrokeWidth(12.0f);
            pt.setStyle(Paint.Style.STROKE);
            canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt);
        } 
    } 
 
    public void cancelExpandHelper() { 
        if (mExpandHelper != null) {
            mExpandHelper.cancel();
        } 
    } 
} 
 
8
CodeRank
This code example shows how to use the following methods:drawPath, drawRect, drawText
    @Override 
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(BG_COLOR);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
 
        paint.setColor(FILTER_COLOR);
        Path path = new Path();
        path.moveTo(getWidth() * (0.5f - 0.5f * start / max), 0);
        path.lineTo(getWidth() * (0.5f + 0.5f * start / max), 0);
        path.lineTo(getWidth() * (0.5f + 0.5f * end / max), getHeight());
        path.lineTo(getWidth() * (0.5f - 0.5f * end / max), getHeight());
        path.close();
        canvas.drawPath(path, paint);
 
        paint.setColor(TEXT_COLOR);
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setTextSize(16);
        canvas.drawText(Integer.toString(end), getWidth() / 2, getHeight() / 2, paint);

8
CodeRank
This code example shows how to use the following methods:drawBitmap, drawRect, translate
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
 
            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);
             
            mBitmapPaint.setAlpha(127);
            canvas.translate(0.0f, mBitmap2.getHeight());
            canvas.translate(0.0f, 25.0f);
            canvas.drawBitmap(mBitmap1, 0.0f, 0.0f, mBitmapPaint);
             
            mBitmapPaint.setAlpha(255);
            canvas.translate(0.0f, mBitmap1.getHeight());
            canvas.translate(0.0f, 25.0f);

8
CodeRank
This code example shows how to use the following methods:concat, drawRect, getHeight, getWidth, restoreToCount
    mController.initializeEffects();
  } 
 
  @Override 
  protected void dispatchDraw(Canvas canvas) {
    final int saveCount = canvas.save();
    final Matrix m = mController.getEffectsMatrix();
    if (!m.isIdentity())
      canvas.concat(m);
 
    final float alpha = mController.getEffectsAlpha();
    if (alpha != 1f)
      canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int)(255 * alpha), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
 
    super.dispatchDraw(canvas);
 
    final int fadeFactor = mController.getFadeFactor();
    if (fadeFactor > 0) {
      mFadePaint.setColor(Color.argb(fadeFactor, 0, 0, 0));
      canvas.drawRect(0, 0, getWidth(), getHeight(), mFadePaint);

8
CodeRank
This code example shows how to use the following methods:drawBitmap, drawColor, drawRect, setBitmap
8
CodeRank
This code example shows how to use the following methods:drawColor, drawRect, drawText, getClipBounds, restore
    /** 
     * @see android.view.View#onDraw(android.graphics.Canvas) 
     */ 
    @Override 
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);
 
        canvas.save();
        transformation.transform(canvas);
        drawable.draw(canvas);
        canvas.restore();
 
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        Rect r = canvas.getClipBounds();
        canvas.drawRect(r, paint);
 
        paint.setTextSize(10);
        paint.setColor(Color.BLUE);

8
CodeRank

Related Canvas drawRect Questions & Answers:

drawRect Method Overview
Draw the specified Rect using the specified paint.
See Code Examples for other Android Canvas Methods: