protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); canvas.save (); canvas.translate (10, 10); // translate (1 point) doDraw (canvas, new float[] { 0, 0 }, new float[] { 5, 5 }); canvas.restore (); canvas.save (); canvas.translate (160, 10); // rotate/uniform-scale (2 points) doDraw (canvas, new float[] { 32, 32, 64, 32 }, new float[] { 32, 32, 64, 48 }); canvas.restore (); canvas.save (); canvas.translate (10, 110); // rotate/skew (3 points) doDraw (canvas, new float[] { 0, 0, 64, 0, 0, 64 }, new float[] { 0, 0, 96, 0, 24, 64 }); canvas.restore (); canvas.save (); canvas.translate (160, 110); // perspective (4 points) doDraw (canvas, new float[] { 0, 0, 64, 0, 64, 64, 0, 64 }, new float[] { 0, 0, 96, 0, 64, 96, 0, 64 }); canvas.restore (); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFCCCCCC)); canvas.concat (mMatrix); canvas.drawBitmapMesh (mBitmap, WIDTH, HEIGHT, mVerts, 0, null, 0, null); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.GRAY); canvas.save (); canvas.translate (80, 5); drawOriginalRects (canvas, 0xFF); canvas.restore (); mPaint.setStyle (Paint.Style.FILL); canvas.save (); canvas.translate (0, 140); drawRgn (canvas, Color.RED, "Union", Region.Op.UNION); canvas.restore (); canvas.save (); canvas.translate (0, 280); drawRgn (canvas, Color.BLUE, "Xor", Region.Op.XOR); canvas.restore (); canvas.save (); canvas.translate (160, 140); drawRgn (canvas, Color.GREEN, "Difference", Region.Op.DIFFERENCE); canvas.restore (); canvas.save (); canvas.translate (160, 280); drawRgn (canvas, Color.WHITE, "Intersect", Region.Op.INTERSECT); canvas.restore (); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); canvas.translate (10, 10); canvas.save (); for (int i = 0; i < N; i++) { setSrcR (i); drawSrcR (canvas, i); canvas.translate (mSrcR.width () + 15, 0); } canvas.restore (); canvas.translate (0, 100); for (int j = 0; j < sFits.Length; j++) { canvas.save (); for (int i = 0; i < N; i++) { drawFit (canvas, i, sFits [j]); canvas.translate (mDstR.width () + 8, 0); } canvas.drawText (sFitLabels [j], 0, HEIGHT * 2 / 3, mLabelPaint); canvas.restore (); canvas.translate (0, 80); } }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFDDDDDD)); Paint paint = new Paint (); paint.setAntiAlias (true); paint.setStyle (Paint.Style.STROKE); paint.setStrokeWidth (3); paint.setStyle (Paint.Style.FILL); RectF r = new RectF (); float t, x, y; t = GetAnimScalar (25, 500); canvas.translate (320, 240); for (int i = 0; i < 35; i++) { paint.setColor (unchecked((int)0xFFF00FF0 - i * 0x04000000)); double step = Math.PI / (55 - i); double angle = t * step; x = (20 + i * 5) * (float)Math.Sin (angle); y = (20 + i * 5) * (float)Math.Cos (angle); r.set (x, y, x + 10, y + 10); canvas.drawRect (r, paint); } }
protected override void onDraw (Canvas canvas) { Paint paint = mPaint; float x = 20; float y = 20; canvas.drawColor (Color.WHITE); paint.setColorFilter (null); canvas.drawBitmap (mBitmap, x, y, paint); ColorMatrix cm = new ColorMatrix (); mAngle += 2; if (mAngle > 180) { mAngle = 0; } //convert our animated angle [-180...180] to a contrast value of [-1..1] float contrast = mAngle / 180.0f; setContrast (cm, contrast); paint.setColorFilter (new ColorMatrixColorFilter (cm)); canvas.drawBitmap (mBitmap, x + mBitmap.getWidth () + 10, y, paint); setContrastScaleOnly (cm, contrast); paint.setColorFilter (new ColorMatrixColorFilter (cm)); canvas.drawBitmap (mBitmap, x, y + mBitmap.getHeight () + 10, paint); setContrastTranslateOnly (cm, contrast); paint.setColorFilter (new ColorMatrixColorFilter (cm)); canvas.drawBitmap (mBitmap, x, y + 2 * (mBitmap.getHeight () + 10), paint); }
static void test_alphagradients (Canvas canvas) { canvas.translate (20, 10); RectF r = new RectF (10, 10, 410, 30); Paint p = new Paint (), p2 = new Paint (); p2.setStyle (Paint.Style.STROKE); using (Shader shader = setgrad (r, 0xFF00FF00, 0x0000FF00)) p.setShader (shader); canvas.drawRect (r, p); canvas.drawRect (r, p2); r.offset (0, r.height () + 4); using (Shader shader = setgrad(r, 0xFF00FF00, 0x00000000)) p.setShader (shader); canvas.drawRect (r, p); canvas.drawRect (r, p2); r.offset (0, r.height () + 4); using (Shader shader = setgrad(r, 0xFF00FF00, 0x00FF0000)) p.setShader (shader); canvas.drawRect (r, p); canvas.drawRect (r, p2); }
static void drawCentered (Canvas c, Rect r, Paint p) { float inset = p.getStrokeWidth () * 0.5f; if (inset == 0) { // catch hairlines inset = 0.5f; } c.drawRect (r.left + inset, r.top + inset, r.right - inset, r.bottom - inset, p); }
void showPath (Canvas canvas, int x, int y, Path.FillType ft, Paint paint) { canvas.save (); canvas.translate (x, y); canvas.clipRect (0, 0, 120, 120); canvas.drawColor (Color.WHITE); mPath.setFillType (ft); canvas.drawPath (mPath, paint); canvas.restore (); }
// create a bitmap with a rect, used for the "src" image static Bitmap makeSrc (int w, int h) { Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); Paint p = new Paint (Paint.ANTI_ALIAS_FLAG); p.setColor (unchecked((int)0xFF66AAFF)); c.drawRect (w / 3, h / 3, w * 19 / 20, h * 19 / 20, p); return bm; }
// create a bitmap with a circle, used for the "dst" image static Bitmap makeDst (int w, int h) { Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888); Canvas c = new Canvas (bm); Paint p = new Paint (Paint.ANTI_ALIAS_FLAG); p.setColor (unchecked((int)0xFFFFCC44)); c.drawOval (new RectF (0, 0, w * 3 / 4, h * 3 / 4), p); return bm; }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); mDrawable.setBounds (mRect); float r = 16; canvas.save (); canvas.translate (10, 10); mDrawable.setGradientType (GradientDrawable.LINEAR_GRADIENT); setCornerRadii (mDrawable, r, r, 0, 0); mDrawable.draw (canvas); canvas.restore (); canvas.save (); canvas.translate (10 + mRect.width () + 10, 10); mDrawable.setGradientType (GradientDrawable.RADIAL_GRADIENT); setCornerRadii (mDrawable, 0, 0, r, r); mDrawable.draw (canvas); canvas.restore (); canvas.translate (0, mRect.height () + 10); canvas.save (); canvas.translate (10, 10); mDrawable.setGradientType (GradientDrawable.SWEEP_GRADIENT); setCornerRadii (mDrawable, 0, r, r, 0); mDrawable.draw (canvas); canvas.restore (); canvas.save (); canvas.translate (10 + mRect.width () + 10, 10); mDrawable.setGradientType (GradientDrawable.LINEAR_GRADIENT); setCornerRadii (mDrawable, r, 0, 0, r); mDrawable.draw (canvas); canvas.restore (); canvas.translate (0, mRect.height () + 10); canvas.save (); canvas.translate (10, 10); mDrawable.setGradientType (GradientDrawable.RADIAL_GRADIENT); setCornerRadii (mDrawable, r, 0, r, 0); mDrawable.draw (canvas); canvas.restore (); canvas.save (); canvas.translate (10 + mRect.width () + 10, 10); mDrawable.setGradientType (GradientDrawable.SWEEP_GRADIENT); setCornerRadii (mDrawable, 0, r, 0, r); mDrawable.draw (canvas); canvas.restore (); }
protected override void onDraw (Canvas canvas) { Console.WriteLine ("DRAW: {0} {1}", canvas.getWidth (), canvas.getHeight ()); RectF r = new RectF (0, 0, canvas.getWidth (), canvas.getHeight ()); Paint paint = new Paint (); using (Shader shader = make_grad (canvas.getWidth(), canvas.getHeight())) paint.setShader (shader); canvas.drawRect (r, paint); }
void drawOriginalRects (Canvas canvas, int alpha) { mPaint.setStyle (Paint.Style.STROKE); mPaint.setColor (Color.RED); mPaint.setAlpha (alpha); drawCentered (canvas, mRect1, mPaint); mPaint.setColor (Color.BLUE); mPaint.setAlpha (alpha); drawCentered (canvas, mRect2, mPaint); // restore style mPaint.setStyle (Paint.Style.FILL); }
void drawFit (Canvas canvas, int index, Matrix.ScaleToFit stf) { canvas.save (); setSrcR (index); mMatrix.setRectToRect (mSrcR, mDstR, stf); canvas.concat (mMatrix); drawSrcR (canvas, index); canvas.restore (); canvas.drawRect (mDstR, mHairPaint); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); Paint p = new Paint (); float y = 10; p.setColor (Color.RED); canvas.drawBitmap (mBitmap, 10, y, p); y += mBitmap.getHeight () + 10; canvas.drawBitmap (mBitmap2, 10, y, p); y += mBitmap2.getHeight () + 10; p.setShader (mShader); canvas.drawBitmap (mBitmap3, 10, y, p); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFCCCCCC)); canvas.save (); canvas.concat (mMatrix); canvas.drawVertices (Canvas.VertexMode.TRIANGLE_FAN, 10, mVerts, 0, mTexs, 0, null, 0, null, 0, 0, mPaint); canvas.translate (0, 240); canvas.drawVertices (Canvas.VertexMode.TRIANGLE_FAN, 10, mVerts, 0, mTexs, 0, null, 0, mIndices, 0, 6, mPaint); canvas.restore (); }
void drawScene (Canvas canvas) { canvas.clipRect (0, 0, 100, 100); canvas.drawColor (Color.WHITE); mPaint.setColor (Color.RED); canvas.drawLine (0, 0, 100, 100, mPaint); mPaint.setColor (Color.GREEN); canvas.drawCircle (30, 70, 30, mPaint); mPaint.setColor (Color.BLUE); canvas.drawText ("Clipping", 100, 30, mPaint); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); canvas.translate (10, 10); canvas.saveLayerAlpha (0, 0, 200, 200, 0x88, LAYER_FLAGS); mPaint.setColor (Color.RED); canvas.drawCircle (75, 75, 75, mPaint); mPaint.setColor (Color.BLUE); canvas.drawCircle (125, 125, 75, mPaint); canvas.restore (); }
protected override void onDraw (Canvas canvas) { Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); canvas.drawColor (unchecked((int)0xFFCCCCCC)); canvas.translate (20, 20); paint.setAntiAlias (true); showPath (canvas, 0, 0, Path.FillType.WINDING, paint); showPath (canvas, 160, 0, Path.FillType.EVEN_ODD, paint); showPath (canvas, 0, 160, Path.FillType.INVERSE_WINDING, paint); showPath (canvas, 160, 160, Path.FillType.INVERSE_EVEN_ODD, paint); }
protected override void onDraw (Canvas canvas) { Paint paint = new Paint (); canvas.translate (10, 10); canvas.drawColor (Color.WHITE); paint.setColor (Color.RED); paint.setStrokeWidth (0); canvas.drawLines (mPts, paint); paint.setColor (Color.BLUE); paint.setStrokeWidth (3); canvas.drawPoints (mPts, paint); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.GRAY); canvas.save (); canvas.translate (10, 10); drawScene (canvas); canvas.restore (); canvas.save (); canvas.translate (160, 10); canvas.clipRect (10, 10, 90, 90); canvas.clipRect (30, 30, 70, 70, Region.Op.DIFFERENCE); drawScene (canvas); canvas.restore (); canvas.save (); canvas.translate (10, 160); mPath.reset (); canvas.clipPath (mPath); // makes the clip empty mPath.addCircle (50, 50, 50, Path.Direction.CCW); canvas.clipPath (mPath, Region.Op.REPLACE); drawScene (canvas); canvas.restore (); canvas.save (); canvas.translate (160, 160); canvas.clipRect (0, 0, 60, 60); canvas.clipRect (40, 40, 100, 100, Region.Op.UNION); drawScene (canvas); canvas.restore (); canvas.save (); canvas.translate (10, 310); canvas.clipRect (0, 0, 60, 60); canvas.clipRect (40, 40, 100, 100, Region.Op.XOR); drawScene (canvas); canvas.restore (); canvas.save (); canvas.translate (160, 310); canvas.clipRect (0, 0, 60, 60); canvas.clipRect (40, 40, 100, 100, Region.Op.REVERSE_DIFFERENCE); drawScene (canvas); canvas.restore (); }
static void drawIntoBitmap (Bitmap bm) { float x = bm.getWidth (); float y = bm.getHeight (); Canvas c = new Canvas (bm); Paint p = new Paint (); p.setAntiAlias (true); p.setAlpha (0x80); c.drawCircle (x / 2, y / 2, x / 2, p); p.setAlpha (0x30); p.setXfermode (new PorterDuffXfermode (PorterDuff.Mode.SRC)); p.setTextSize (60); p.setTextAlign (Paint.Align.CENTER); Paint.FontMetrics fm = p.getFontMetrics (); c.drawText ("Alpha", x / 2, (y - fm.ascent) / 2, p); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); RectF bounds = new RectF (); mPath.computeBounds (bounds, false); canvas.translate (10 - bounds.left, 10 - bounds.top); makeEffects (mEffects, mPhase); mPhase += 1; for (int i = 0; i < mEffects.Length; i++) { mPaint.setPathEffect (mEffects [i]); mPaint.setColor (mColors [i]); canvas.drawPath (mPath, mPaint); canvas.translate (0, 28); } }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFDDDDDD)); Paint paint = new Paint (); paint.setAntiAlias (true); paint.setStyle (Paint.Style.STROKE); paint.setStrokeWidth (3); paint.setStyle (Paint.Style.FILL); RectF r = new RectF (10, 10, 110, 110); for (int i = 0; i < 256; ++i) { canvas.translate (1, 1); paint.setColor ((int)(0xFF000000 + i * 0x00010000)); canvas.drawRect (r, paint); } }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFDDDDDD)); canvas.save (); Paint paint = new Paint (); paint.setColor (Color.BLUE); MaskFilter mf = new BlurMaskFilter (128, BlurMaskFilter.Blur.NORMAL); paint.setMaskFilter (mf); mf.Dispose (); canvas.translate (200, 200); canvas.drawCircle (100, 100, 200, paint); canvas.restore (); paint.Dispose (); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (Color.WHITE); drawArcs (canvas, mBigOval, mUseCenters [mBigIndex], mPaints [mBigIndex]); for (int i = 0; i < 4; i++) { drawArcs (canvas, mOvals [i], mUseCenters [i], mPaints [i]); } mSweep += SWEEP_INC; if (mSweep > 360) { mSweep -= 360; mStart += START_INC; if (mStart >= 360) { mStart -= 360; } mBigIndex = (mBigIndex + 1) % mOvals.Length; } }
protected override void onDraw(Canvas canvas) { canvas.drawColor(Color.YELLOW); int width = canvas.getWidth(); int height = canvas.getHeight(); Paint paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(10); canvas.drawCircle(width / 2, height / 2, height / 3, paint); Paint inner = new Paint(); paint.setColor(Color.GREEN); paint.setStyle(Paint.Style.FILL); canvas.drawCircle(width / 2, height / 2, height / 3 - 10, inner); Paint text = new Paint(); text.setTextSize(20); canvas.drawText("I am a Xobot Monkey!", width / 8, height / 8, text); }
void drawRgn (Canvas canvas, int color, String str, Region.Op op) { if (str != null) { mPaint.setColor (Color.BLACK); canvas.drawText (str, 80, 24, mPaint); } Region rgn = new Region (); rgn.set (mRect1); rgn.op (mRect2, op); mPaint.setColor (color); RegionIterator iter = new RegionIterator (rgn); Rect r = new Rect (); canvas.translate (0, 30); mPaint.setColor (color); while (iter.next(r)) { canvas.drawRect (r, mPaint); } drawOriginalRects (canvas, 0x80); }
protected override void onDraw (Canvas canvas) { canvas.drawColor (unchecked((int)0xFFDDDDDD)); Paint paint = new Paint (); paint.setAntiAlias (true); paint.setStyle (Paint.Style.STROKE); paint.setStrokeWidth (10); EmbossMaskFilter mf = new EmbossMaskFilter (new float[] { 1, 1, 1 }, 128, 16 * 2, 4); paint.setMaskFilter (mf); mf.Dispose (); // paint.setMaskFilter(new SkEmbossMaskFilter(fLight, SkIntToScalar(4)))->unref(); // paint.setShader(new SkColorShader(SK_ColorBLUE))->unref(); paint.setDither (true); canvas.drawCircle (50, 50, 30, paint); paint.Dispose (); }