跟ios一样,还是解决分享长微博问题,在网上搜过一些方法,测试都有问题,后来根据起方法进行改进,形成该方法;现在在项目中应用,目前没有发现大得问题。
现分享一下。
public static Bitmap textAsBitmap(String text, float textSize) {
TextPaint textPaint = new TextPaint();
// textPaint.setARGB(0x31, 0x31, 0x31, 0);
textPaint.setColor(Color.BLACK);
textPaint.setTextSize(textSize);
StaticLayout layout = new StaticLayout(text, textPaint, 450,
Alignment.ALIGN_NORMAL, 1.3f, 0.0f, true);
Bitmap bitmap = Bitmap.createBitmap(layout.getWidth() + 20,
layout.getHeight() + 20, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(10, 10);
canvas.drawColor(Color.WHITE);
layout.draw(canvas);
Log.d("textAsBitmap",
String.format("1:%d %d", layout.getWidth(), layout.getHeight()));
return bitmap;
}