Refine search
Bitmap newBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig()); Canvas canvas = new Canvas(newBitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(image, 0, 0, null);
protected void onDraw(Canvas canvas){ final String s = "Hello. I'm some text!"; Paint p = new Paint(); Rect bounds = new Rect(); p.setTextSize(60); p.getTextBounds(s, 0, s.length(), bounds); float mt = p.measureText(s); int bw = bounds.width(); Log.i("LCG", String.format( "measureText %f, getTextBounds %d (%s)", mt, bw, bounds.toShortString()) ); bounds.offset(0, -bounds.top); p.setStyle(Style.STROKE); canvas.drawColor(0xff000080); p.setColor(0xffff0000); canvas.drawRect(bounds, p); p.setColor(0xff00ff00); canvas.drawText(s, 0, bounds.bottom, p); }
public class CustomView extends View{ private Paint paint; private int w; private int h; public CustomView(Context context, AttributeSet attr) { super(context, attr); paint = new Paint(); paint.setTextAlign(Align.CENTER); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { this.w = w; this.h = h; super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { canvas.drawColor(Color.WHITE); canvas.drawText("TEST", w/2, h/2, paint); } }
_Path = new Path(); _BitmapPaint = new Paint(Paint.DITHER_FLAG); _paint = new Paint(); _paint.setAntiAlias(true); _paint.setDither(true); _paint.setColor(Color.argb(255, 0, 0, 0)); _paint.setStyle(Paint.Style.STROKE); _paint.setStrokeJoin(Paint.Join.ROUND); protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); canvas.drawBitmap(_Bitmap, 0, 0, _BitmapPaint); canvas.drawPath(_Path, _paint); _Canvas.drawColor(Color.WHITE); invalidate();
@Override public void onDraw(Canvas canvas) { Paint paint = new Paint(); Bitmap kangoo = BitmapFactory.decodeResource(getResources(), R.drawable.kangoo); canvas.drawColor(Color.BLACK); canvas.drawBitmap(kangoo, 10, 10, null); }
/** * Draws the provided path in filled mode with the provided color and alpha. * Special thanks to Angelo Suzuki (https://github.com/tinsukE) for this. * * @param c * @param filledPath * @param fillColor * @param fillAlpha */ protected void drawFilledPath(Canvas c, Path filledPath, int fillColor, int fillAlpha) { int color = (fillAlpha << 24) | (fillColor & 0xffffff); if (clipPathSupported()) { int save = c.save(); c.clipPath(filledPath); c.drawColor(color); c.restoreToCount(save); } else { // save Paint.Style previous = mRenderPaint.getStyle(); int previousColor = mRenderPaint.getColor(); // set mRenderPaint.setStyle(Paint.Style.FILL); mRenderPaint.setColor(color); c.drawPath(filledPath, mRenderPaint); // restore mRenderPaint.setColor(previousColor); mRenderPaint.setStyle(previous); } }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.parseColor("#ff000000")); if (mRect == null) mRect = new Rect(); if (mPaint == null) { mPaint = new Paint(); mPaint.setColor(Color.parseColor("#3b3b3b")); } mRect.left = 0; mRect.right = getWidth(); mRect.top = 0; mRect.bottom = Math.round(getHeight() * progress * 1.0f / 100); canvas.drawRect(mRect, mPaint); }
mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint);
result = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(result); Paint paint = new Paint(); canvas.drawColor(Color.BLACK); canvas.drawBitmap(mImage, 15, 15, paint);
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final View thisView = this; canvas.drawColor(COLOR_BACKGROUND); mMountPaint.setColor(COLOR_MOUNTAIN_1); canvas.drawPath(mMount1, mMountPaint); canvas.save(); canvas.scale(-1, 1, thisView.getWidth() / 2, 0); drawTree(canvas, 0.12f * mScaleX, 180 * mScaleX, (93 + 20 * mMoveFactor) * mScaleY, COLOR_TREE_3_BRINK, COLOR_TREE_3_BRANCH); drawTree(canvas, 0.1f * mScaleX, 200 * mScaleX, (96 + 20 * mMoveFactor) * mScaleY, COLOR_TREE_3_BRINK, COLOR_TREE_3_BRANCH); canvas.restore(); mMountPaint.setColor(COLOR_MOUNTAIN_2); canvas.drawPath(mMount2, mMountPaint); drawTree(canvas, 0.2f * mScaleX, 160 * mScaleX, (105 + 30 * mMoveFactor) * mScaleY, COLOR_TREE_1_BRINK, COLOR_TREE_1_BRANCH); drawTree(canvas, 0.14f * mScaleX, 180 * mScaleX, (105 + 30 * mMoveFactor) * mScaleY, COLOR_TREE_2_BRINK, COLOR_TREE_2_BRANCH); drawTree(canvas, 0.16f * mScaleX, 140 * mScaleX, (105 + 30 * mMoveFactor) * mScaleY, COLOR_TREE_2_BRINK, COLOR_TREE_2_BRANCH); mMountPaint.setColor(COLOR_MOUNTAIN_3); canvas.drawPath(mMount3, mMountPaint); }
private Bitmap addWhiteBorder(Bitmap bmp, int borderSize) { Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig()); Canvas canvas = new Canvas(bmpWithBorder); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bmp, borderSize, borderSize, null); return bmpWithBorder; }
return SCHEMA + f.getPath(); Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(220); paint.setAntiAlias(true); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.parseColor(color)); Rect rect = new Rect(); paint.getTextBounds(s, 0, s.length(), rect);
ourBlue; = new Paint(); textPaint = new Paint(); ourBlue.setColor(Color.BLUE); textPaint.setARGB(50,100,100,250); textPaint.setTextAlign(Align.CENTER); protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); canvas.drawBitmap(pBall, (canvas.getWidth()/2), changingY, null); if (changingY <canvas.getHeight()){ changingY += 10;
Canvas canvas = new Canvas(canvasBitmap); canvas.drawColor(Color.TRANSPARENT); BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.loading); Bitmap yourBitmap = bd.getBitmap(); Paint paint = new Paint(); canvas.drawBitmap(yourBitmap, 0, 0, paint);
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(0); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); }
this.hexagonBorderPath = new Path(); this.mBorderPaint = new Paint(); this.mBorderPaint.setColor(Color.WHITE); this.mBorderPaint.setStrokeCap(Paint.Cap.ROUND); c.drawPath(hexagonBorderPath, mBorderPaint); c.clipPath(hexagonPath, Region.Op.INTERSECT); c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); super.onDraw(c);
protected void onDraw(Canvas canvas) { if (count <= 1) { this.setVisibility(View.GONE); return; } float height = getHeight(); float radius = height * DESIGN_INDICATOR_RADIUS / DESIGN_BOTTOM_HEIGHT; float distance = height * DESIGN_INDICATOR_DISTANCE / DESIGN_BOTTOM_HEIGHT; float windowWidth = radius * 2 * count + distance * (count - 1); float left = (getWidth() - windowWidth) / 2; float cy = height / 2; canvas.drawColor(0xffffffff); Paint paint = new Paint(); paint.setAntiAlias(true); for (int i = 0; i < count; i++) { if (i == current) { paint.setColor(0xff5d71a0); } else { paint.setColor(0xffafb1b7); } float cx = left + (radius * 2 + distance) * i; canvas.drawCircle(cx, cy, radius, paint); } }
setContentView(new MyView(this)); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setColor(color); protected void onDraw(Canvas canvas) { Bitmap viewBgrnd = BitmapFactory.decodeResource(FingerPaint.this.getResources(),R.drawable.icon); canvas.drawBitmap(viewBgrnd, 0, 0, mPaint); canvas.drawColor(0xFFAAAAAA); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);