List of usage examples for android.graphics Paint setFlags
public void setFlags(int flags)
From source file:Main.java
private static Bitmap getResizeBitmap(View view, Bitmap bitmap) { Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / sScaleFactor), (int) (view.getMeasuredHeight() / sScaleFactor), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(overlay); canvas.translate(-view.getLeft() / sScaleFactor, -view.getTop() / sScaleFactor); canvas.scale(1 / sScaleFactor, 1 / sScaleFactor); Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG); canvas.drawBitmap(bitmap, 0, 0, paint); return overlay; }
From source file:Main.java
public static Bitmap drawViewToBitmap(View view, int width, int height, float translateX, float translateY, int downSampling, String color) { float scale = 1f / downSampling; int bmpWidth = (int) (width * scale - translateX / downSampling); int bmpHeight = (int) (height * scale - translateY / downSampling); Bitmap dest = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dest); canvas.translate(-translateX / downSampling, -translateY / downSampling); if (downSampling > 1) { canvas.scale(scale, scale);//from w w w . j a v a 2s.c o m } Paint paint = new Paint(); paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.parseColor(color), PorterDuff.Mode.SRC_ATOP); paint.setColorFilter(filter); view.buildDrawingCache(); Bitmap cache = view.getDrawingCache(); canvas.drawBitmap(cache, 0, 0, paint); cache.recycle(); view.destroyDrawingCache(); return dest; }
From source file:com.raspi.chatapp.util.Notification.java
private Bitmap getLargeIcon(int bgColor, char letter, float width, boolean round) { Bitmap b = Bitmap.createBitmap((int) width, (int) width, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); RectF mInnerRectF = new RectF(); mInnerRectF.set(0, 0, width, width); mInnerRectF.offset(0, 0);/* ww w.ja va 2 s. c om*/ Paint mBgPaint = new Paint(); mBgPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mBgPaint.setStyle(Paint.Style.FILL); mBgPaint.setColor(bgColor); TextPaint mTitleTextPaint = new TextPaint(); mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTitleTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); mTitleTextPaint.setTextAlign(Paint.Align.CENTER); mTitleTextPaint.setLinearText(true); mTitleTextPaint.setColor(Color.WHITE); mTitleTextPaint.setTextSize(width * 0.8f); float centerX = mInnerRectF.centerX(); float centerY = mInnerRectF.centerY(); int xPos = (int) centerX; int yPos = (int) (centerY - (mTitleTextPaint.descent() + mTitleTextPaint.ascent()) / 2); if (round) c.drawOval(mInnerRectF, mBgPaint); else c.drawRect(mInnerRectF, mBgPaint); c.drawText(String.valueOf(letter), xPos, yPos, mTitleTextPaint); return b; }
From source file:de.treichels.hott.ui.android.html.AndroidCurveImageGenerator.java
private Bitmap getBitmap(final Curve curve, final float scale, final boolean description) { final boolean pitchCurve = curve.getPoint()[0].getPosition() == 0; final float scale1 = scale * 0.75f; // smaller images on the android // platform/*from w w w . ja v a 2 s .co m*/ final Bitmap image = Bitmap.createBitmap((int) (10 + 200 * scale1), (int) (10 + 250 * scale1), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(image); final Paint backgroundPaint = new Paint(); backgroundPaint.setColor(Color.WHITE); backgroundPaint.setStyle(Style.FILL); final Paint forgroundPaint = new Paint(); forgroundPaint.setColor(Color.BLACK); forgroundPaint.setStyle(Style.STROKE); forgroundPaint.setStrokeWidth(1.0f); forgroundPaint.setStrokeCap(Cap.BUTT); forgroundPaint.setStrokeJoin(Join.ROUND); forgroundPaint.setStrokeMiter(0.0f); final Paint curvePaint = new Paint(forgroundPaint); curvePaint.setFlags(Paint.ANTI_ALIAS_FLAG); curvePaint.setStrokeWidth(2.0f); final Paint pointPaint = new Paint(curvePaint); pointPaint.setStrokeWidth(5.0f); pointPaint.setStyle(Style.FILL_AND_STROKE); final Paint helpLinePaint = new Paint(forgroundPaint); helpLinePaint.setColor(Color.GRAY); helpLinePaint.setPathEffect(new DashPathEffect(new float[] { 5.0f, 5.0f }, 2.5f)); final Paint textPaint = new Paint(forgroundPaint); textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); textPaint.setTextSize(12.0f); textPaint.setTextAlign(Align.CENTER); textPaint.setStyle(Style.FILL); canvas.drawRect(0, 0, 10 + 200 * scale1, 10 + 250 * scale1, backgroundPaint); canvas.drawRect(5, 5, 5 + 200 * scale1, 5 + 250 * scale1, forgroundPaint); canvas.drawLine(5, 5 + 25 * scale1, 5 + 200 * scale1, 5 + 25 * scale1, helpLinePaint); canvas.drawLine(5, 5 + 225 * scale1, 5 + 200 * scale1, 5 + 225 * scale1, helpLinePaint); if (!pitchCurve) { canvas.drawLine(5, 5 + 125 * scale1, 5 + 200 * scale1, 5 + 125 * scale1, helpLinePaint); canvas.drawLine(5 + 100 * scale1, 5, 5 + 100 * scale1, 5 + 250 * scale1, helpLinePaint); } if (curve.getPoint() != null) { int numPoints = 0; for (final CurvePoint p : curve.getPoint()) { if (p.isEnabled()) { numPoints++; } } final double[] xVals = new double[numPoints]; final double[] yVals = new double[numPoints]; int i = 0; for (final CurvePoint p : curve.getPoint()) { if (p.isEnabled()) { if (i == 0) { xVals[i] = pitchCurve ? 0 : -100; } else if (i == numPoints - 1) { xVals[i] = 100; } else { xVals[i] = p.getPosition(); } yVals[i] = p.getValue(); if (description) { float x0; float y0; if (pitchCurve) { x0 = (float) (5 + xVals[i] * 2 * scale1); y0 = (float) (5 + (225 - yVals[i] * 2) * scale1); } else { x0 = (float) (5 + (100 + xVals[i]) * scale1); y0 = (float) (5 + (125 - yVals[i]) * scale1); } canvas.drawPoint(x0, y0, pointPaint); if (y0 < 5 + 125 * scale1) { canvas.drawRect(x0 - 4, y0 + 5, x0 + 3, y0 + 18, backgroundPaint); canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 + 16, textPaint); } else { canvas.drawRect(x0 - 4, y0 - 5, x0 + 3, y0 - 18, backgroundPaint); canvas.drawText(Integer.toString(p.getNumber() + 1), x0 - 1, y0 - 7, textPaint); } } i++; } } if (numPoints > 2 && curve.isSmoothing()) { final SplineInterpolator s = new SplineInterpolator(); final PolynomialSplineFunction function = s.interpolate(xVals, yVals); float x0 = 5; float y0; if (pitchCurve) { y0 = (float) (5 + (225 - yVals[0] * 2) * scale1); } else { y0 = (float) (5 + (125 - yVals[0]) * scale1); } while (x0 < 4 + 200 * scale1) { final float x1 = x0 + 1; float y1; if (pitchCurve) { y1 = (float) (5 + (225 - function.value((x1 - 5) / scale1 / 2) * 2) * scale1); } else { y1 = (float) (5 + (125 - function.value((x1 - 5) / scale1 - 100)) * scale1); } canvas.drawLine(x0, y0, x1, y1, curvePaint); x0 = x1; y0 = y1; } } else { for (i = 0; i < numPoints - 1; i++) { float x0, y0, x1, y1; if (pitchCurve) { x0 = (float) (5 + xVals[i] * 2 * scale1); y0 = (float) (5 + (225 - yVals[i] * 2) * scale1); x1 = (float) (5 + xVals[i + 1] * 2 * scale1); y1 = (float) (5 + (225 - yVals[i + 1] * 2) * scale1); } else { x0 = (float) (5 + (100 + xVals[i]) * scale1); y0 = (float) (5 + (125 - yVals[i]) * scale1); x1 = (float) (5 + (100 + xVals[i + 1]) * scale1); y1 = (float) (5 + (125 - yVals[i + 1]) * scale1); } canvas.drawLine(x0, y0, x1, y1, curvePaint); } } } return image; }
From source file:com.abhinavjhanwar.android.egg.neko.Cat.java
public Bitmap createLargeBitmap(Context context) { final Resources res = context.getResources(); final int w = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); final int h = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(result); final Paint pt = new Paint(); float[] hsv = new float[3]; Color.colorToHSV(mBodyColor, hsv); hsv[2] = (hsv[2] > 0.5f) ? (hsv[2] - 0.25f) : (hsv[2] + 0.25f); pt.setColor(Color.HSVToColor(hsv)); pt.setFlags(Paint.ANTI_ALIAS_FLAG); float r = w / 2; canvas.drawCircle(r, r, r, pt);/*from w ww . j a v a 2 s. c om*/ int m = w / 10; slowDraw(canvas, m, m, w - m - m, h - m - m); return result; }
From source file:github.daneren2005.dsub.util.ImageLoader.java
private Bitmap createUnknownImage(int size, int primaryColor, String topText, String bottomText) { Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint color = new Paint(); color.setColor(primaryColor);/*w w w .j av a 2 s. c o m*/ canvas.drawRect(0, 0, size, size * 2.0f / 3.0f, color); color.setShader(new LinearGradient(0, 0, 0, size / 3.0f, Color.rgb(82, 82, 82), Color.BLACK, Shader.TileMode.MIRROR)); canvas.drawRect(0, size * 2.0f / 3.0f, size, size, color); if (topText != null || bottomText != null) { Paint font = new Paint(); font.setFlags(Paint.ANTI_ALIAS_FLAG); font.setColor(Color.WHITE); font.setTextSize(3.0f + size * 0.07f); if (topText != null) { canvas.drawText(topText, size * 0.05f, size * 0.6f, font); } if (bottomText != null) { canvas.drawText(bottomText, size * 0.05f, size * 0.8f, font); } } return bitmap; }
From source file:com.lt.adamlee.aagame.GameView.java
public void about(Canvas c) { int textsize = (int) F.hf(20.0f); Paint p3 = new Paint(); p3.setTypeface(tf);//from w w w .j a v a2 s. co m p3.setColor(ViewCompat.MEASURED_STATE_MASK); p3.setFlags(1); p3.setTextSize((float) textsize); Paint pagepaint = new Paint(); pagepaint.setColor(getResources().getColor(R.color.abc_secondary_text_material_light)); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, pagepaint); p3.setTextSize(F.hf(30.0f)); c.drawText(ctx.getString(R.string.about), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.about)) / 2.0f), (float) (screenH / 4), p3); p3.setTextSize((float) textsize); c.drawText(ctx.getString(R.string.app_name), ((float) (screenW / 2)) - (p3.measureText(ctx.getString(R.string.app_name)) / 2.0f), (float) (((textsize * 2) + 1) + ((screenH - (textsize * 7)) / 2)), p3); c.drawText("License Version 1.7", ((float) (screenW / 2)) - (p3.measureText("License Version 1.7") / 2.0f), (float) (((textsize * 3) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Powered by Map Game Studio", ((float) (screenW / 2)) - (p3.measureText("Powered by Map Game Studio") / 2.0f), (float) (((textsize * 4) + 1) + ((screenH - (textsize * 7)) / 2)), p3); p3.setTextSize(F.hf(17.0f)); c.drawText("Email:mapgamestudio@gmail.com", ((float) (screenW / 2)) - (p3.measureText("Email:mapgamestudio@gmail.com") / 2.0f), (float) (((textsize * 5) + 1) + ((screenH - (textsize * 7)) / 2)), p3); }
From source file:com.lt.adamlee.aagame.GameView.java
public void help(Canvas c) { String x = ""; float textsize = F.hf(19.0f); Paint p4 = new Paint(); Paint p5 = new Paint(); Paint p6 = new Paint(); String text = ctx.getString(R.string.helptext); p4.setColor(getResources().getColor(R.color.bright_foreground_inverse_material_light)); p4.setFlags(1); p5.setTypeface(tf);/*w w w . j a v a2 s . c o m*/ p5.setTextSize(F.hf(30.0f)); p6.setTextSize(textsize); p5.setColor(ViewCompat.MEASURED_STATE_MASK); c.drawRect(0.0f, 0.0f, (float) screenW, (float) screenH, p4); c.drawText(ctx.getString(R.string.help), ((float) (screenW / 2)) - (p5.measureText(ctx.getString(R.string.help)) / 2.0f), (float) (screenH / 8), p5); int i = 0; int xv1 = 0; int yv1 = (int) textsize; while (i < ctx.getString(R.string.helptext).length()) { if (text.charAt(i) != '$') { c.drawText(" " + ctx.getString(R.string.helptext).charAt(i), (float) xv1, ((float) ((screenH / 8) + yv1)) + (4.0f * textsize), p6); xv1 = (int) (((float) xv1) + p6.measureText(Character.toString(ctx.getString(R.string.helptext).charAt(i)))); } if (ctx.getString(R.string.helptext).charAt(i) == '$') { i++; x = " "; yv1 = (int) (((float) yv1) + textsize); xv1 = 0; } i++; } }