public Bitmap cropCircle(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth()/2, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
public RadarChartRenderer(RadarChart chart, ChartAnimator animator, ViewPortHandler viewPortHandler) { super(animator, viewPortHandler); mChart = chart; mHighlightPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mHighlightPaint.setStyle(Paint.Style.STROKE); mHighlightPaint.setStrokeWidth(2f); mHighlightPaint.setColor(Color.rgb(255, 187, 115)); mWebPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mWebPaint.setStyle(Paint.Style.STROKE); mHighlightCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG); }
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 LineChartRenderer(LineDataProvider chart, ChartAnimator animator, ViewPortHandler viewPortHandler) { super(animator, viewPortHandler); mChart = chart; mCirclePaintInner = new Paint(Paint.ANTI_ALIAS_FLAG); mCirclePaintInner.setStyle(Paint.Style.FILL); mCirclePaintInner.setColor(Color.WHITE); }
protected PaintDrawable() { mPaint.setStyle(Paint.Style.FILL); mPaint.setAntiAlias(true); mPaint.setColor(0xffaaaaaa); }
dv = new DrawingView(this); setContentView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); super(c); context=c; mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); circlePaint = new Paint(); circlePath = new Path(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); super.onDraw(canvas); mPath.reset();
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = pixels; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } }
int framesCountAvg=0; long framesTimer=0; Paint fpsPaint=new Paint(); dBgrY = 1; //Scrolling background speed fpsPaint.setTextSize(30); bgrW = bgr.getWidth(); bgrH = bgr.getHeight(); switch (ev.getAction()) { ballX = (int) ev.getX() - ballW/2; ballY = (int) ev.getY() - ballH/2; Rect fromRect1 = new Rect(0, 0, bgrW - bgrScroll, bgrH); Rect toRect1 = new Rect(bgrScroll, 0, bgrW, bgrH); Rect fromRect2 = new Rect(bgrW - bgrScroll, 0, bgrW, bgrH); Rect toRect2 = new Rect(0, 0, bgrScroll, bgrH); canvas.drawBitmap(bgr, fromRect1, toRect1, null); canvas.drawBitmap(bgrReverse, fromRect2, toRect2, null); canvas.drawBitmap(bgr, fromRect2, toRect2, null); canvas.drawBitmap(bgrReverse, fromRect1, toRect1, null);
mPaint.setShader(s); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(32); mCenterPaint.setColor(color); mCenterPaint.setStrokeWidth(5); float r = CENTER_X - mPaint.getStrokeWidth()*0.5f; int c = mCenterPaint.getColor(); mCenterPaint.setStyle(Paint.Style.STROKE); mCenterPaint.setAlpha(0xFF); } else { mCenterPaint.setAlpha(0x80); CENTER_RADIUS + mCenterPaint.getStrokeWidth(), mCenterPaint); mCenterPaint.setStyle(Paint.Style.FILL); mCenterPaint.setColor(c); mCenterPaint.setColor(interpColor(mColors, unit)); invalidate(); if (mTrackingCenter) { if (inCenter) { mListener.colorChanged(mCenterPaint.getColor());
mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setTextSize(16); mPaint.setTextAlign(Paint.Align.CENTER); mPaint.setTypeface(futura_bold); Paint.FontMetrics fm = mPaint.getFontMetrics(); mPaintTextOffset = (fm.descent + fm.ascent) * 0.5f; if (mPaint.getColor() == 0xFF000000) { mPaint.setColor(0xFFFFFFFF); mPaint2.setColor(0xFF000000); } else { mPaint.setColor(0xFF000000); mPaint2.setColor(0xFFFFFFFF); mPaint2.setAlpha(0); final float size = mPaint.measureText("Label"); if((int) size > (r.right-r.left)) { float ts = mPaint.getTextSize(); Log.w("DEBUG","Text size was"+ts); mPaint.setTextSize(ts-2); if (mPaint.getColor() == 0xFFFFFFFF) { mModeIndex = (mModeIndex + 1) % mModes.length; updateTitle();
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int roundPixels, Rect srcRect, Rect destRect, int width, int height) { Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(output); final Paint paint = new Paint(); final RectF destRectF = new RectF(destRect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xFF000000); canvas.drawRoundRect(destRectF, roundPixels, roundPixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, srcRect, destRectF, paint); return output; } }
mv = new MyView(this); setContentView(mv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setARGB(255, 0, 0, 0); mPaint.setStyle(Paint.Style.STROKE); mPaint.setPathEffect(new DashPathEffect(new float[]{10, 40,}, 0)); mPaint.setStrokeWidth(12); super(c); context = c; mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); mPath.moveTo(0, h / 2); mPath.quadTo(w / 2, h / 2, w, h / 2); protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint);
private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(android.graphics.Color.BLACK); canvas.drawPaint(paint); paint.setStrokeWidth(4); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); Point a = new Point(0, 0); Point b = new Point(0, 100); Point c = new Point(87, 50); Path path = new Path(); path.setFillType(FillType.EVEN_ODD); path.lineTo(b.x, b.y); path.lineTo(c.x, c.y); path.lineTo(a.x, a.y); path.close(); canvas.drawPath(path, paint); }
paint.setStrokeWidth(2); paint.setColor(android.graphics.Color.RED); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setAntiAlias(true); mapView.getProjection().toPixels(point3, point3_draw); Path path = new Path(); path.setFillType(Path.FillType.EVEN_ODD); path.moveTo(point1_draw.x,point1_draw.y); path.lineTo(point2_draw.x,point2_draw.y); path.lineTo(point3_draw.x,point3_draw.y);
super.draw(canvas, mapv, shadow); Paint mPaint = new Paint(); mPaint.setDither(true); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(2); Path path = new Path(); projection.toPixels(gP2, p2); path.moveTo(p2.x, p2.y); path.lineTo(p1.x,p1.y); canvas.drawPath(path, mPaint);
public BitmapDrawable writeOnDrawable(int drawableId, String text){ Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.BLACK); paint.setTextSize(20); Canvas canvas = new Canvas(bm); canvas.drawText(text, 0, bm.getHeight()/2, paint); return new BitmapDrawable(bm); }
final Drawable drawable = PathsDrawable.this; final Rect bounds = drawable.getBounds(); final int width = bounds.width(); final int height = bounds.height(); if (mPaint.getAlpha() == 0xFF) { canvas.save(); canvas.translate(bounds.left-mStartX, bounds.top-mStartY); if (mPaths != null) { for (int i = 0; i < mPaths.size(); i++) { if (mColors != null && i < mColors.size()) { mPaint.setColor(mColors.get(i)); canvas.drawPath(mPaths.get(i), mPaint); mPaint.setAlpha(0xFF); canvas.restore(); createCachedBitmapIfNeeded(width, height); if (mCacheDirty) { mCachedBitmap.eraseColor(Color.TRANSPARENT); Canvas tmpCanvas = new Canvas(mCachedBitmap); drawCachedBitmap(tmpCanvas);
private Bitmap createBitmapWithRedCircle(int width, int height) { int minEdge = Math.min(width, height); float radius = minEdge / 2f; Bitmap result = Bitmap.createBitmap(minEdge, minEdge, Bitmap.Config.ARGB_8888); result.setHasAlpha(true); Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.RED); canvas.drawCircle(radius, radius, radius, paint); return result; }
Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setAntiAlias(true); paint.setStyle(Paint.Style.STROKE); Path path = new Path();