(
Context context,
String code,
int size,
int color
)
| 38 | private static final String FONT_PATH = "font/icon.ttf"; |
| 39 | |
| 40 | public static Bitmap get( |
| 41 | Context context, |
| 42 | String code, |
| 43 | int size, |
| 44 | int color |
| 45 | ) { |
| 46 | if (paint == null) { |
| 47 | paint = new Paint(); |
| 48 | paint.setAntiAlias(true); |
| 49 | paint.setTypeface( |
| 50 | Typeface.createFromAsset(context.getAssets(), FONT_PATH) |
| 51 | ); |
| 52 | paint.setTextAlign(Paint.Align.CENTER); |
| 53 | } |
| 54 | |
| 55 | paint.setTextSize(size); |
| 56 | paint.setColor(color); |
| 57 | |
| 58 | float baseline = -paint.ascent(); |
| 59 | int width = (int) paint.measureText(code, 0, code.length()); |
| 60 | int height = (int) (baseline + paint.descent()); |
| 61 | Bitmap bitmap = Bitmap.createBitmap( |
| 62 | width, |
| 63 | height, |
| 64 | Bitmap.Config.ARGB_8888 |
| 65 | ); |
| 66 | Canvas canvas = new Canvas(bitmap); |
| 67 | |
| 68 | canvas.drawText(code, width / 2, baseline, paint); |
| 69 | return bitmap; |
| 70 | } |
| 71 | |
| 72 | public static Bitmap get( |
| 73 | Context context, |
no test coverage detected