How to convert text into bitmap in android? I am facing an issue where I need to convert text to bitmap so that I can create the mirror image of the text.
Asked
Active
Viewed 971 times
2 Answers
1
this is how you get a bitmap from a view. (I assumed that with 'text' you were referring to textview
private static Bitmap get_view_image(View view) {
int w = view.getWidth();
int h = view.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawColor(Color.WHITE);
Drawable bgDrawable = view.getBackground();
if (bgDrawable!=null) {
bgDrawable.draw(canvas);
}
else {
canvas.drawColor(Color.WHITE);
}
view.draw(canvas);
return bmp;
}

Cristian Holdunu
- 1,880
- 1
- 18
- 43
0
You can directly mirror the bitmap (if you have one) using
BitmapDrawable flip(BitmapDrawable d)
{
Matrix m = new Matrix();
m.preScale(-1, 1);
Bitmap src = d.getBitmap();
Bitmap dst = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), m, false);
dst.setDensity(DisplayMetrics.DENSITY_DEFAULT);
return new BitmapDrawable(dst);
}

Sunil Mishra
- 3,796
- 1
- 27
- 40