List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:Main.java
public static void drawShade(Canvas canvas, RectF bounds) { int w = canvas.getWidth(); int h = canvas.getHeight(); Paint p = new Paint(); p.setStyle(Paint.Style.FILL); p.setColor(Color.BLACK & 0x88000000); RectF r = new RectF(); r.set(0, 0, w, bounds.top);/*w w w .j a va 2 s. co m*/ canvas.drawRect(r, p); r.set(0, bounds.top, bounds.left, h); canvas.drawRect(r, p); r.set(bounds.left, bounds.bottom, w, h); canvas.drawRect(r, p); r.set(bounds.right, bounds.top, w, bounds.bottom); canvas.drawRect(r, p); }
From source file:Main.java
public static Bitmap getBitmap(Bitmap background, Bitmap contour, float alpha) { Paint paint = new Paint(); paint.setAntiAlias(true);//from w ww .j av a 2 s. c o m paint.setColor(Color.WHITE); paint.setDither(false); Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Matrix m = new Matrix(); m.setScale(contour.getWidth() * 1.0f / background.getWidth(), contour.getHeight() * 1.0f / background.getHeight()); paint.setAlpha((int) (alpha * 0xff)); canvas.drawBitmap(background, m, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); paint.setAlpha(0xff); canvas.drawBitmap(contour, 0, 0, paint); return bitmap; }
From source file:Main.java
public static Bitmap roundCorners(final Bitmap source, final float radius) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true);// w w w .java 2 s .c o m paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
From source file:Main.java
public static Bitmap circleBitmap(final Bitmap source) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true);//w w w .j a v a 2 s .c o m paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); final float radius = width > height ? height / 2 : width / 2; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
From source file:Main.java
public static Bitmap roundCorner(Bitmap src, float round) { int width = src.getWidth(); int height = src.getHeight(); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawARGB(0, 0, 0, 0);/*from w ww. j a v a 2 s . c o m*/ final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLACK); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); canvas.drawRoundRect(rectF, round, round, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(src, rect, rect, paint); return result; }
From source file:Main.java
public static Bitmap roundCorners(final Bitmap bitmap, final int radiusX, final int radiusY) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true);/*from w w w.j a va 2 s . co m*/ paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); canvas.drawRoundRect(new RectF(0, 0, width, height), radiusX, radiusY, paint); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(bitmap, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); return rounded; }
From source file:Main.java
public static void drawRuleOfThird(Canvas canvas, RectF bounds) { Paint p = new Paint(); p.setStyle(Paint.Style.STROKE); p.setColor(Color.argb(128, 255, 255, 255)); p.setStrokeWidth(2);//ww w . jav a2 s .c o m float stepX = bounds.width() / 3.0f; float stepY = bounds.height() / 3.0f; float x = bounds.left + stepX; float y = bounds.top + stepY; for (int i = 0; i < 2; i++) { canvas.drawLine(x, bounds.top, x, bounds.bottom, p); x += stepX; } for (int j = 0; j < 2; j++) { canvas.drawLine(bounds.left, y, bounds.right, y, p); y += stepY; } }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { OutputStream outStream = null; Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }//from w ww.j av a 2s .c om String dataPath = Environment.getExternalStorageDirectory().toString() + "/SignChat/Temp/temp" + "0" + pictureNum + ".jpg"; try { FileOutputStream out = new FileOutputStream(dataPath); // NEWLY ADDED CODE STARTS HERE [ Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.WHITE); // Text Color paint.setStrokeWidth(12); // Text Size paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // Text // Overlapping // Pattern // some more settings... canvas.drawBitmap(bitmap, 0, 0, paint); canvas.drawText("Testing...", 10, 10, paint); // NEWLY ADDED CODE ENDS HERE ] bitmap.compress(CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap getRounded(Bitmap bm, int cornerRadiusPx) { int w = bm.getWidth(); int h = bm.getHeight(); Bitmap bmOut = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmOut); Paint paint = new Paint(); paint.setAntiAlias(true);//ww w .j a v a 2 s . c om paint.setColor(0xff424242); Rect rect = new Rect(0, 0, w, h); RectF rectF = new RectF(rect); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, cornerRadiusPx, cornerRadiusPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bm, rect, rect, paint); return bmOut; }
From source file:Main.java
static Bitmap generatorContactCountIcon(Context context, Bitmap icon) { int iconSize = (int) context.getResources().getDimension(android.R.dimen.app_icon_size); Bitmap contactIcon = Bitmap.createBitmap(iconSize, iconSize, Config.ARGB_8888); Canvas canvas = new Canvas(contactIcon); Paint iconPaint = new Paint(); iconPaint.setDither(true);/* www.j ava 2s .c o m*/ iconPaint.setFilterBitmap(true); Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight()); Rect dst = new Rect(0, 0, iconSize, iconSize); canvas.drawBitmap(icon, src, dst, iconPaint); int contacyCount = 11; Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); countPaint.setColor(Color.RED); countPaint.setTextSize(20f); countPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(String.valueOf(contacyCount), iconSize - 18, 25, countPaint); return contactIcon; }