此示例正确用于将文本转换为图像左对齐(TextPaint.Align.LEFT) 但在更改时,它变为TextPaint.Align.RIGHT转换后的图像为空。
Convert text to image file on Android
这是我的代码:
final TextPaint textPaint = new TextPaint()
{
{
setColor(Color.rgb(0, 0, 0));
setTextAlign(TextPaint.Align.RIGHT);
setTextSize(textSize);
setTypeface(NormalFont(getApplicationContext()));
setAntiAlias(true);
}
};
final Rect bounds = new Rect();
textPaint.getTextBounds(text, 0, text.length(), bounds);
final Bitmap bmp = Bitmap.createBitmap(bounds.width(), bounds.height()+buttonPadding, Bitmap.Config.ARGB_8888); //use ARGB_8888 for better quality //RGB_565
final Canvas canvas = new Canvas(bmp);
canvas.drawText(text, 0, textSize, textPaint);
return bmp;
}