private Bitmap fromText(String text) {
int dpSize = 12;//dp
float pixel =TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, dpSize, this.getResources().getDisplayMetrics());
Paint paint = new Paint();
paint.setTextSize(pixel);
paint.setTextAlign(Paint.Align.LEFT);
paint.setAlpha(77);
paint.setColor(Color.WHITE);
Paint.FontMetricsInt fm = paint.getFontMetricsInt();
int width = (int) paint.measureText(text);
int height = fm.descent - fm.ascent;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawText(text, 0, fm.leading - fm.ascent, paint);
canvas.save();
return bitmap;
}
Android 创建Bitmap