Привет, я хочу преобразовать String в Bitmap, и все хорошо, но я не знаю, как установить результат. Изображение подходит для текста. Как я могу это сделать? Вот мой код:Преобразование String в Bitmap (android)
public Bitmap textAsBitmap(String text, float textSize, float stroke,
int color, Typeface typeface) {
TextPaint paint = new TextPaint();
paint.setColor(color);
paint.setTextSize(textSize);
paint.setStrokeWidth(stroke);
paint.setTypeface(typeface);
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.LEFT);
float baseline = (int) (-paint.ascent() + 3f);
StaticLayout staticLayout = new StaticLayout(text, 0, text.length(),
paint, 435, android.text.Layout.Alignment.ALIGN_NORMAL, 1.0f,
1.0f, false);
int linecount = staticLayout.getLineCount();
int height = (int) (baseline + paint.descent() + 3) * linecount + 10;
Bitmap image = Bitmap
.createBitmap(****MY WIDTH***, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawARGB(0xFF, 0xFF, 0xFF, 0xFF);
staticLayout.draw(canvas);
return image;
}
Я даже попытался это, но он не работает должным образом:
final Rect bounds = new Rect();
paint.getTextBounds(text, 0, text.length(), bounds);
Bitmap image = Bitmap
.createBitmap(bounds.width(), height, Bitmap.Config.ARGB_8888);
, пожалуйста, помогите!