List of usage examples for android.graphics Paint setTextAlign
public void setTextAlign(Align align)
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true);//from ww w . j a v a 2s . c om paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); return new BitmapDrawable(res, buffer); }
From source file:Main.java
private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize, final int color) { final Paint paint = new Paint(); paint.setAntiAlias(true);//from ww w. j a v a 2 s . c o m paint.setTextAlign(Align.CENTER); paint.setTextSize(textSize); paint.setColor(color); final Rect bounds = new Rect(); paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, MORE_SUGGESTIONS_HINT.length(), bounds); final int width = Math.round(bounds.width() + 0.5f); final int height = Math.round(bounds.height() + 0.5f); final Bitmap buffer = Bitmap.createBitmap(width, (height * 3 / 2), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint); BitmapDrawable bitmapDrawable = new BitmapDrawable(res, buffer); bitmapDrawable.setTargetDensity(canvas); return bitmapDrawable; }
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 w w.j a v a 2 s .co m*/ 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 Bitmap text2Bitmap(String text, int color, float size) { if (TextUtils.isEmpty(text)) { return null; }/*w ww. ja va 2 s .com*/ Paint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); paint.setTextSize(size); paint.setColor(color); paint.setTextAlign(Paint.Align.LEFT); float baseline = -paint.ascent(); int width = (int) (paint.measureText(text) + 0.5f); int height = (int) (baseline + paint.descent() + 0.5f); Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(image); canvas.drawText(text, 0, baseline, paint); return image; }
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. ja v a 2 s .c om*/ paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); return paint; }
From source file:Main.java
public static BitmapDrawable writeOnDrawable(Activity actv, Resources res, int drawableId, String text, int textSize) { Bitmap bm = BitmapFactory.decodeResource(res, drawableId).copy(Bitmap.Config.ARGB_8888, true); DisplayMetrics dm = new DisplayMetrics(); actv.getWindowManager().getDefaultDisplay().getMetrics(dm); int pixelSize = (int) ((textSize * dm.scaledDensity)); if (text.length() > 2) { pixelSize = (int) ((textSize * dm.scaledDensity) * (0.5 - (text.length() / 10))); }//from ww w . j a v a2s . com Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.WHITE); paint.setTextSize(pixelSize); paint.setTextAlign(Paint.Align.CENTER); // float adjust = paint.measureText(text); Canvas canvas = new Canvas(bm); int xPos = (int) ((bm.getWidth() / 2)); int yPos = (int) ((bm.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)); canvas.drawText(text, xPos, yPos, paint); return new BitmapDrawable(res, bm); }
From source file:Main.java
public static Bitmap getTextImage(String text, float size, int width, int height) { final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Paint paint = new Paint(); final Canvas canvas = new Canvas(bmp); canvas.drawColor(Color.WHITE); paint.setColor(Color.BLACK);//from w w w.j a v a 2 s. co m paint.setStyle(Style.FILL); paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); paint.setTextSize(size); paint.setTypeface(Typeface.DEFAULT); canvas.drawText(text, width / 2, height / 2, paint); return bmp; }
From source file:Main.java
public static Bitmap buildSequence(Context context, String text) { Bitmap myBitmap = Bitmap.createBitmap(160, 84, Bitmap.Config.ARGB_4444); Canvas myCanvas = new Canvas(myBitmap); Paint paint = new Paint(); //Typeface font = Typeface.createFromAsset(context.getAssets(),"fonts/7LED.ttf"); paint.setAntiAlias(true);/* w w w . jav a 2s.c o m*/ paint.setSubpixelText(true); //paint.setTypeface(font); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.YELLOW); paint.setTextSize(65); paint.setTextAlign(Paint.Align.CENTER); myCanvas.drawText(text, 80, 60, paint); return myBitmap; }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static Bitmap getDefaultAvatarInitials(Context context, String text) { Log.e(TAG, "getDefaultAvatarInitials"); String initials = getInitials(text); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);/* w w w .j a v a 2 s . co m*/ paint.setTextSize(36); paint.setStrokeWidth(4); paint.setTextAlign(Paint.Align.CENTER); Bitmap bm = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); canvas.drawColor(context.getResources().getColor(R.color.material_blue_300)); int distanceFromBaseline = (int) ((paint.descent() + paint.ascent()) / 2); int xPos = (canvas.getWidth() / 2); int yPos = (canvas.getHeight() / 2) - distanceFromBaseline; canvas.drawText(initials, xPos, yPos, paint); return bm; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER); paint.setTextSize(scale * 14);//from w w w. jav a 2 s .c om paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2; canvas.drawText(text, x, y, paint); return bitmap; }