List of usage examples for android.graphics Paint setTypeface
public Typeface setTypeface(Typeface typeface)
From source file:Main.java
public static Bitmap int2Icon(Context context, int i) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), 0x7f020047); Bitmap bitmap1 = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap1); Paint paint = new Paint(); paint.setDither(true);// w ww . jav a 2s. c om paint.setFilterBitmap(true); canvas.drawBitmap(bitmap, 0.0F, 0.0F, paint); bitmap.recycle(); Paint paint1 = new Paint(257); paint1.setColor(-1); paint1.setTypeface(Typeface.DEFAULT_BOLD); paint1.setTextAlign(android.graphics.Paint.Align.CENTER); canvas.drawText(String.valueOf(i), bitmap.getWidth() / 2, 3 + bitmap.getHeight() / 2, paint1); return bitmap1; }
From source file:Main.java
public static Paint getScoreColor() { Paint paint = new Paint(); paint.setColor(Color.WHITE);// w w w .jav a2 s. c o m paint.setTextSize(80); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setShadowLayer(3, 5, 5, Color.BLACK); return paint; }
From source file:Main.java
public static Paint getGameOverColor() { Paint paint = new Paint(); paint.setColor(Color.WHITE);//w ww . j a v a 2 s . c o m paint.setTextSize(80); paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setShadowLayer(2, 3, 3, Color.GRAY); return paint; }
From source file:Main.java
public static Paint getGameOverRestartMessageColor() { Paint paint = new Paint(); paint.setColor(Color.YELLOW); paint.setTextSize(20);/*ww w . j a va2 s .c o m*/ paint.setTypeface(Typeface.DEFAULT_BOLD); // paint.setShadowLayer(2, 3, 3, Color.WHITE); return paint; }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context context, int resId, String text) { Resources resources = context.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, resId); Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null) bitmapConfig = Bitmap.Config.ARGB_8888; bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(context.getResources().getColor(android.R.color.white)); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); paint.setTextSize((int) (12 * scale)); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 4; int y = (bitmap.getHeight() + bounds.height()) / 5; canvas.drawText(text, x * scale, y * scale, paint); return bitmap; }
From source file:Main.java
/** * The most useful answer about text drawing ever. http://stackoverflow.com/a/32081250 *///w ww . j a v a 2s . c o m @Nullable public static Bitmap createTypefaceBitmap(final Context context, @NonNull final String text, final int color, final float textSizePx) { final Typeface robotoMedium = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(robotoMedium); paint.setStyle(Paint.Style.FILL); paint.setColor(color); paint.setTextSize(textSizePx); final Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); Bitmap bitmap = null; if (!bounds.isEmpty()) { final int width = bounds.width(); final int height = bounds.height(); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); final float x = bounds.left; final float y = height - bounds.bottom; final Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); } return bitmap; }
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);//from w w w . ja va 2 s.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; }
From source file:Main.java
/** * Create round, coloured bitmap with text embedded. * @param circleColor The color to use.// w w w. j a v a2 s. co m * @param diameterDP The diameter of the circle. * @param text The text to embed. * @return Bitmap showing a text. */ public static Bitmap generateCircleBitmap(int circleColor, float diameterDP, String text) { /** * * http://stackoverflow.com/questions/31168636/rounded-quickcontactbadge-with-text */ final int textColor = 0xffffffff; DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); float diameterPixels = diameterDP * (metrics.densityDpi / 160f); float radiusPixels = diameterPixels / 2; // Create the bitmap Bitmap output = Bitmap.createBitmap((int) diameterPixels, (int) diameterPixels, Bitmap.Config.ARGB_8888); // Create the canvas to draw on Canvas canvas = new Canvas(output); canvas.drawARGB(0, 0, 0, 0); // Draw the circle final Paint paintC = new Paint(); paintC.setAntiAlias(true); paintC.setColor(circleColor); canvas.drawCircle(radiusPixels, radiusPixels, radiusPixels, paintC); // Draw the text if (text != null && text.length() > 0) { final Paint paintT = new Paint(); paintT.setColor(textColor); paintT.setAntiAlias(true); paintT.setTextSize(radiusPixels * 2); paintT.setTypeface(Typeface.SANS_SERIF); final Rect textBounds = new Rect(); paintT.getTextBounds(text, 0, text.length(), textBounds); canvas.drawText(text, radiusPixels - textBounds.exactCenterX(), radiusPixels - textBounds.exactCenterY(), paintT); } return output; }
From source file:Main.java
private static Paint getTextPaint(float size) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setShadowLayer(1, 1, 1, 0xFF000000); paint.setColor(0xFFFFFFFF);//from w w w .j av a2 s .c o m paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); return paint; }
From source file:android.support.v17.leanback.app.ErrorSupportFragment.java
private static FontMetricsInt getFontMetricsInt(TextView textView) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(textView.getTextSize()); paint.setTypeface(textView.getTypeface()); return paint.getFontMetricsInt(); }