0
我需要從數據庫讀取文本/字符串並將其轉換爲圖像。我嘗試了下面的代碼,但我只得到空白圖像。請幫忙Android - 將字符串轉換爲圖像
public Bitmap textAsBitmap(String text, float largest, int textColor) {
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(textColor);
// int width = (int) (paint.measureText(text) + 0.5f); // round
paint.setAntiAlias(true);
paint.setTypeface(Typeface.MONOSPACE);
paint.setTextSize(16);
int width = 400;
// float baseline = (int) (paint.ascent() + 0.5f) + 3f;
// int height = (int) ((baseline + paint.descent() + 0.5f) + 3);
int height = 400;
Bitmap image = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(image);
canvas.drawText(text, 0, 5, paint);
return image;
}
如果將位置參數設置爲類似200,100的值,它會起作用嗎? (只要確保文本不會在位圖之外結束) – Jave 2012-04-12 09:51:59